I want to force the add of a filed in the req.body, according to the scope of the credentials. I have 2 Apps (App1 and App2), and based on who is using my API, I want to programmatically add a field in the req. So credentials of App1 has scope app1
, and app2
in App2's scopes.
Moreover, I have 2 Environments, with different endpoints. Both App has access to both Ends (using different credentials). So I first choose the Env (using dev_env
or my_env
scope), then I verify which App is accessing (checking app1
or app2
scope).
To do that, I use expression apiEndpoint.scopes.indexOf('app1')>=0
. that actually is not working, since the condition is always false. So for debugging purpose, I put the content of apiEndpoint.scopes
as additional field in the req.body
, to see what there is in that.
And I see that apiEndpoint.scopes
has just ["my_env"]
, not "app1". Why?
So I have
http:
port: ${PORT:-8080}
host: ${HOST:-localhost}
apiEndpoints:
myEndpoint:
host: "*"
scopes: ["my_env"] # I explain just this one here
devEndpoint:
host: "*"
scopes: ["dev_env"]
serviceEndpoints:
myEndpoint:
url: 'https://myserver'
policies:
- basic-auth
- cors
- expression
- key-auth
- request-transformer
- rewrite
- oauth2
- proxy
- rate-limit
pipelines:
myEndpoint:
apiEndpoints:
- myEndpoint
policies:
- request-transformer:
-
condition:
name: allOf
conditions:
- # check if scope 'app1' is present. expression not working
#name: expression
#expression: "apiEndpoint.scopes.indexOf('app1')>=0"
action:
body:
add:
available_scopes: "apiEndpoint.scopes" # debug of available scopes.
And the content of req.body is
{"available_scopes": ["my_env"]}
'app1' is missing!
==== update 1
If in req.body.available_scopes
field I put "consumer", I got this:
{
"type": "application",
"isActive": true,
"id": "....",
"userId": "...",
"name": "...",
"company": "...",
"authorizedScopes": [
"my_env"
]
}
So it talks about "authorizedScopes", where are the others? How could I see them? Thanks