I have an existing API which generates an access token and that access token would be usedwhile invoking other rest APIs, So how can i make use of apigee proxy to generate token by passing username and passwords in the rest api.
e.g :
Rest API : [centos@ank-vm ~]$ curl -X GET --header "Tenant: xyz" -u abc:def "http://180.148.27.101/api/v3.1/tokens"
Response :
{"role": "sys_admin", "value": "WyIyIiwiNDRiZjk5ODYwNGMzZjcwNjE3YzRjMDRlYWU4OTRkOTciXQ.DmG0ug.yPNEzNA9QSmADGlU4bRGzz5TSGY"}[centos@ank-vm ~]$
[centos@ank-vm ~]$
How can i generate the access token using apigee ?
Solved! Go to Solution.
Hi @Ankit Goel, if you just want to pass info & call your STS to get token & then hit the target.
Use an Service Callout Policy. Here you can set the Headers to call the Tokens endpoint, get the token & the call your target endpoint.
<ServiceCallout async="false" continueOnError="false" enabled="true" name="Service-Callout-1"> <DisplayName>Custom label used in UI</DisplayName> <Request clearPayload="true" variable="myRequest"> <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables> <Set> <Headers> <Header name="Tenant">xyz</Header> <Headers/> <QueryParams/> <FormParams> <FormParam name="username">abc</FormParam> <FormParam name="password">xyz</FormParam> </FormParams> <Verb>GET</Verb> </Set> </Request> <Response>calloutResponse</Response> <Timeout>60000</Timeout> <HTTPTargetConnection> <URL>http://180.148.27.101/api/v3.1/tokens</URL> </HTTPTargetConnection> </ServiceCallout>
Use Extract Variable policy to get the token,
<ExtractVariables name="ExtractVariables-3"> <Source>calloutResponse</Source> <JSONPayload> <Variable name="token""> <JSONPath>$.value</JSONPath> </Variable> </JSONPayload> <VariablePrefix>oauth</VariablePrefix> </ExtractVariables>
Then use an Assign Message Policy to set the extracted token as Header before hitting your target,
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <AssignMessage async="false" continueOnError="false" enabled="true" name="a_name"> <DisplayName>a_display_name</DisplayName> <AssignTo createNew="false" transport="http" type="request"/> <Set> <Headers> <Header name="Authorization">{oauth.token}</Header> <Headers/> </Set> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> </AssignMessage>