Add OAuth v2.0 Policy to Generate Access Tokens
Attach an OAuth v2.0 policy to the API Proxy in GenerateAccessToken mode. This
policy defines the token endpoint, issues OAuth access tokens using the
client_credentials
grant type, and returns them in the response for use
by external consumers.
- Select API proxy and click Policies.
- Click Edit.
- Select ProxyEndpoint.
- Select PreFlow.
- Under Security Policies, choose OAuth v2.0.
- Click on the + button to add the policy.
- Enter the Policy Name, set the Stream as Incoming Request and click Add.
-
Replace the existing default content in the Body section with the following
policy XML and click Update.
Policy Message:
<OAuthV2 async="false" continueOnError="false" enabled="true" xmlns="http://www.sap.com/apimgmt"> <!-- By default, VerifyAccessToken expects the access token to be sent in an Authorization header. You can change that default using this element<AccessToken> --> <!-- If you want to pass access token in an customer header "access_token": --> <!-- <AccessToken>request.header.access_token</AccessToken> --> <!-- If you want to pass access token in query param "access_token": --> <!-- <AccessToken>request.queryparam.access_token</AccessToken> --> <!-- this flag has to be set when you want to work with third-party access tokens --> <ExternalAuthorization>false</ExternalAuthorization> <!-- valid values are GenerateAccessToken, GenerateAccessTokenImplicitGrant, GenerateAuthorizationCode , RefreshAccessToken , VerifyAccessToken , InvalidateToken , ValidateToken --> <Operation>GenerateAccessToken</Operation> <GenerateResponse enabled="true"/><SupportedGrantTypes> <GrantType>client_credentials</GrantType> </SupportedGrantTypes> <Tokens/> </OAuthV2>
- Click Save.
- In the API Portal, navigate to Develop.
- Click Click to Deploy to apply the changes.