Skip to Content
Author's profile photo Raghavendra Kulkarni

Generate and consume SCP OAuth token in Data Quality API using policies – Part 4

In this blog, we will generate and consume SCP OAuth token in the Data Quality API using policies. As described in the previous blog Part 3 of this series don’t have to generate OAuth token separately

1.  Open Data Quality API which is created as per our previous blog, click on the Policies button

2. Policy editor comes up in read-only mode, switch to edit-mode by clicking on the Edit button

3. We will use Service Callout policy to generate OAuth token, add GetOAuthToken(Service Callout) policy on the PreFlow of the target endpoint

GetOAuthToken-code snippet:

Provide your SCP OAuth token generation URL in the Service callout policy as shown in the above screenshot.

4. To pass credential to OAuth Token endpoint, add  Assign Message & Basic Authentication policies before the Service Callout policy.

GetCredential(Assign Message) policy will store credential and Authorization(Basic Authentication) policy will encode credentials

 

GetCredential-code snippet

Authorisation-code snippet

5. To read the generated OAuth token use extract variable policy. Adding ReadAccessToken(Extract variable) policy after GetOAuthToken.

5.  Finally, let’s provide the OAuth token to the target endpoint by using assign message policy.              Add the SetAccessToken(Assign Message) policy on the Post-flow(incoming request) of the                target endpoint

 

SetAccessToken-code snippet

7.  Save the API, now let’s see if we get the desired result 🙂

As you have already explored API in the API Business Hub, similarly go to the Resources tab in the API & click on GET button of the refData_country.

API Test Console comes, now click on the Send button to see the response.

In the next blog part 5 of this series, we will use API Management Policy Template to achieve the same result, policy template available in the SAP API Business Hub.

 

 

 

 

Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Francisco Ferreira
      Francisco Ferreira

      Hi Raghavendra,

       

      Thanks in advance for your detailed blog, it was very helpful for what i was trying to do.

      Do you know if there is a way (safe if possible) that i could "store" the token and use it while it is valid for the upcoming requests instead of generating and passing a new one to the target endpoint every time i call the API?

       

      thank you once again,

      Best Regards,

      Francisco Ferreira.