I have an internal Web API which exposes JSON. I would like to expose some of the features based on roles of the authenticated user (or machine) from JWT or API-key.
E.g internal API where filter.customerId.eq and filter.vendorId.eq are optional query parameters:
GET /orders?filter.customerId.eq=customer1&filter.vendorId.eq=vendorA
{
"items": [
{
"createdAt": "2022-12-12",
"customerId": "customer1",
"vendorId": "vendorA",
},
{
"createdAt": "2022-01-22",
"customerId": "customer1",
"vendorId": "vendorA",
}
]}
External API for role CUSTOMER should require query parameterfilter.customerId.eq=<ID_OF_AUTHENTICATED_USER>
Eg. GET /orders?filter.customerId.eq=customer1
{
"items": [
{
"createdAt": "2019-02-21",
"customerId": "customer1",
"vendorId": "vendorA",
},
{
"createdAt": "2022-01-22",
"customerId": "customer1",
"vendorId": "vendorB",
},
{
"createdAt": "2022-08-08",
"customerId": "customer1",
"vendorId": "vendorC",
}
]}
External API for role VENDOR should require query parameter filter.vendorId.eq=<ID_OF_AUTHENTICATED_USER>
Eg. GET /orders?filter.vendorId.eq=vendorA
{
"items": [
{
"createdAt": "2019-04-01",
"customerId": "customer999",
"vendorId": "vendorA",
},
{
"createdAt": "2022-01-22",
"customerId": "customer1",
"vendorId": "vendorA",
},
{
"createdAt": "2022-01-22",
"customerId": customer4",
"vendorId": "vendorA",
}
]}
I want to be able to declare the permissions on field level (e.g by in JSON Schema format) to reuse my API endpoint and avoid writing new code (or service, endpoints...) for new roles.
I have built a similar solution. But is there any product, service or open source lib which can do this for me? The API is written in Java and I use MongoDB/Postgres as database.
Related
We have to try to integrate Easyship courier API. And We are facing the below issue.
{
"rates": [],
"messages": [
"Sorry, we couldn't find any shipping solutions based on the information provided."
]
}
For more information, I have shared the request parameter and API response.
API URL:- https://api.easyship.com/v2/rates
Request Parameter:
{
"origin_address": {
"postal_code": "91601",
"city": "Los Ángeles",
"state": "CA",
"country_alpha2": "US"
},
"destination_address": {
"postal_code": "95140",
"city": "Mount Hamilton",
"state": "CA",
"country_alpha2": "US"
},
"parcels": [
{
"total_actual_weight": 5,
"items": [
{
"quantity": 1,
"category": "mobile_phones",
"dimensions": {
"width": 10,
"height": 10,
"length": 25
},
"description": "Apple iPad",
"actual_weight": 5,
"declared_currency": "USD",
"declared_customs_value": 49500.55
}
]
}
]
}
Response Parameter:
{
"status": "failure",
"errors": [
"Sorry, we couldn't find any shipping solutions based on the information provided."
],
"request_id": "545b5f76a41e2994a13f384559dee625",
"timestamp": "2022-10-12T10:09:21.272Z"
}
Note:
This request parameter works with the production access token.
We have applied all possible solutions for this issue but didn't find anything.
Also we don't want to use the production access token because we are in the developing stage. so please please provide working with a sandbox solution.
I have deployed my webhook and connected my WABA. Once I send an image to this business account. It did not return the media id from the response. Actually, the JSON returned to me like this:
{
"entry": [
{
"changes": [
{
"field": "messages",
"value": {
"contacts": [
{
"profile": {
"name": "XXXXXXX"
}
}
],
"messages": [
{
"from": "XXXXXXXXXX",
"id": "wamid.aisjdoiajsodiajsodasd\u003d",
"timestamp": "1657527108",
"type": "image"
}
],
"metadata": {}
}
}
],
"id": "124071984791824"
}
],
"object": "whatsapp_business_account"
}
Or should I try the Whatsapp On-premises API? https://developers.facebook.com/docs/whatsapp/on-premises/reference/media/media-id
You have to chooose the image_id from the request you receive.
like , let media_id=req.body.entry[0].changes[0].value.messages[0].image.id;
you can store this id in DB and use the endpioint where you can get the url for media_id.
Then you can download the image from the URL received and uploaded it anywhere you want.
I built a simple asp.net core application and need to authenticate an account that uses MFA in addition to username & password.
The service I'm trying to log into exposes an authentication endpoint described here:
https://developer.okta.com/docs/reference/api/authn/#request-example-for-primary-authentication-with-public-application
When I provide the username and password it returns the expected JSON:
{
"stateToken": "00zQZJ1ZY3Em2401r4T69Dhx35TdF1VTFP5KRTa8ib",
"expiresAt": "2020-05-30T21:11:14.000Z",
"status": "MFA_REQUIRED",
"_embedded": {
"user": {
"id": "00u10vk1torIgBBxxxxx",
"profile": {
"login": "john.doe#email.com",
"firstName": "John",
"lastName": "Doe",
"locale": "en",
"timeZone": "America/Los_Angeles"
}
},
"factors": [{
"id": "ost1g59468dXOddAE0h8",
"factorType": "token:software:totp",
"provider": "OKTA",
"vendorName": "OKTA",
"profile": {
"credentialId": "john.doe#email.com"
},
"_links": {
"verify": {
"href": "https://company.okta.com/api/v1/authn/factors/ost1g59468dXOddxxxxx/verify",
"hints": {
"allow": ["POST"]
}
}
}
}, {
Does anyone know who I can also add 2FA into the request to get it to work?
I'm trying to get the currently running containers of a service to visualize them like in Portainer.io.
Portainer shows the currently running machines and replicas like 5/8.
I can get desired replica number using engine api with /services endpoint.
What I couldn't find is currently running containers of a service.
Service endpoint returns a result like;
{
"ID": "frf43534t43543t43gt435",
"Version": {
"Index": 10936
},
"CreatedAt": "2019-12-11T14:36:03.361254384Z",
"UpdatedAt": "2019-12-11T14:40:19.911714617Z",
"Spec": {
"Name": "connector-service",
"Labels": {
"com.docker.stack.image": "connector",
"com.docker.stack.namespace": "conn"
},
"TaskTemplate": {
"ContainerSpec": {
"Image": "connector:latest",
"Labels": {
"com.docker.stack.namespace": "conn"
},
"Hostname": "connector-service{{.Task.Slot}}",
"Env": [
"CONNECT_CONFIG_STORAGE_REPLICATION_FACTOR=3",
"CONNECT_STATUS_STORAGE_REPLICATION_FACTOR=3"
],
"Privileges": {
"CredentialSpec": null,
"SELinuxContext": null
},
"Isolation": "default"
},
"Resources": {},
"Placement": {},
"Networks": [
{
"Target": "sfer32432fr4ewt4r3g4tr54",
"Aliases": [
"connector-service"
]
}
],
"ForceUpdate": 0,
"Runtime": "container"
},
"Mode": {
"Replicated": {
"Replicas": 6
}
},
"EndpointSpec": {
"Mode": "vip",
"Ports": [
{
"Protocol": "tcp",
"TargetPort": 8083,
"PublishedPort": 8083,
"PublishMode": "ingress"
}
]
}
},
"Endpoint": {
"Spec": {
"Mode": "vip",
"Ports": [
{
"Protocol": "tcp",
"TargetPort": 8083,
"PublishedPort": 8083,
"PublishMode": "ingress"
}
]
},
"Ports": [
{
"Protocol": "tcp",
"TargetPort": 8083,
"PublishedPort": 8083,
"PublishMode": "ingress"
}
],
"VirtualIPs": [
{
"NetworkID": "safcedsvcsg4425r32dsf",
"Addr": "10.0.0.55/24"
},
{
"NetworkID": "sfsfe4233fr3g435432greg43",
"Addr": "10.0.3.11/24"
}
]
}
}
I've realized that in engine API containers can be retrieved with two endpoints; first one is /containers and second one is /tasks. In order to get running containers of a service /tasks endpoint with two filters can be used for example; http://192.168.4.142:1777/v1.40/tasks?filters={"service":{"my-service":true},"desired-state":{"running":true}}
This endpoint returns total number of running containers for a service, /services endpoint returns desired number so one can find how many of the desired containers are running.
I'm trying to query the TinkerPop server (hosted inside docker container) via CosmosDB client library, which uses under the hood Gremlin.Net. So I managed to connect it and insert the data, here's intercepted WebSocket request:
!application/vnd.gremlin-v1.0+json{
"requestId": "b64bd2eb-46c3-4095-9eef-768bca2a14ed",
"op": "eval",
"processor": "",
"args": {
"gremlin": "g.addV(\"User\").property(\"UserId\",2).property(\"CustomerId\",1)"
}
}
The response:
{
"requestId": "b64bd2eb-46c3-4095-9eef-768bca2a14ed",
"status": {
"message": "",
"code": 200,
"attributes": {
"host": "/172.19.0.1:38848"
}
},
"result": {
"data": [
{
"id": 0,
"label": "User",
"type": "vertex",
"properties": {}
}
],
"meta": {}
}
}
Problem is that I see those properties when I'm connected via gremlin console
gremlin> g.V().hasLabel("User").has("CustomerId",1).has("UserId",2).limit(1).valueMap()
==>{UserId=[2], CustomerId=[1]}
Also, I'm able to query the TinkerPop server with Gremlin.Net:
!application/vnd.gremlin-v1.0+json{
"requestId": "de35909f-4bc1-4aae-aa5f-28361b3c0933",
"op": "eval",
"processor": "",
"args": {
"gremlin": "g.V().hasLabel(\"User\").has(\"CustomerId\",1).has(\"UserId\",2).limit(1)"
}
}
But it returns a payload with zero-valued ID and without any properties included:
{
"requestId": "de35909f-4bc1-4aae-aa5f-28361b3c0933",
"status": {
"message": "",
"code": 200,
"attributes": {
"host": "/172.19.0.1:38858"
}
},
"result": {
"data": [
{
"id": 0,
"label": "User",
"type": "vertex",
"properties": {}
}
],
"meta": {}
}
}
Tried to swap between GraphSON v1, v2, v3 with no luck. Documentation says that script serializers should include all the properties. Do I have to tweak the config somehow to make this work and return properties?
So it seems that with a version of 3.4 of the Gremlin server ReferenceElementStrategy
was added by default to traversals, to preserve compatibility between binary and script serializers. In our case we wanted to mimic the behavior of the CosmosDB, so to adjust and receive desired behavior just remove the strategy from init script (in our case it was empty-sample.groovy
globals << [g : graph.traversal().withStrategies(ReferenceElementStrategy.instance())]
to
globals << [g : graph.traversal()]