3 weeks ago
Hello Experts,
I've setup a REST API proxy that enables access via OAuth 2.0 on the ProxyEndpoint side.
On the TargetEndpoint side I have to authenticate using OAuth 2.0. I've developed the following two policies in order to enable authentication against the TargetEndpoint.
However, since the extract variable policy does not get the variable values, the flow goes into error.
Any help in this regard would be greatly appreciated.
1. Extract Variable policy : It needs to extract the client_id and client_secret into variables which is input from postman as grant type Client_credentials & client_id and client_secret
2. Basic Authentication : It needs to take the get the variables values from step 1 and create a Authorization header.
Extract Variable Code :
<!-- Extract content from the request or response messages, including headers, URI paths, JSON/XML payloads, form parameters, and query parameters -->
<ExtractVariables async="true" continueOnError="false" enabled="true" xmlns='http://www.sap.com/apimgmt'>
<Variable name="clientid" />
<Variable name="clientsecret" />
<Header name="client_id" />
<Header name="client_secret" />
<Source>header</Source>
</ExtractVariables>
Basic Authentication Code:
<BasicAuthentication async='true' continueOnError='false' enabled='true' xmlns='http://www.sap.com/apimgmt'>
<Operation>Encode</Operation>
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<User ref='clientid'></User>
<Password ref='clientsecret'></Password>
<AssignTo createNew="true">sapapim.Authorization</AssignTo>
</BasicAuthentication>
The extract variable does not extract the client_id and client_secret as expected and an error is returned
{
"fault": {
"faultstring": "Unresolved variable : clientid",
"detail": {
"errorcode": "steps.basicauthentication.UnresolvedVariable"
}
}
}
API flow screenshot:
Hello Sneha,
Please update the code for Extract Variable Policy as below and you should be able to extract the variable values as required.
<ExtractVariables async="false" continueOnError="false" enabled="true" xmlns='http://www.sap.com/apimgmt'>
<Source>request</Source>
<Header name="client_id">
<Pattern ignoreCase="true">{clientid}</Pattern>
</Header>
<Header name="client_secret">
<Pattern ignoreCase="true">{clientsecret}</Pattern>
</Header>
</ExtractVariables>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
76 | |
10 | |
10 | |
10 | |
10 | |
9 | |
8 | |
7 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.