18

SAP CPQ REST API Authentication via JWT token in CPI

 3 years ago
source link: https://blogs.sap.com/2021/04/05/sap-cpq-rest-api-authentication-via-jwt-token-in-cpi/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Technical Articles
Posted on April 5, 2021 3 minute read

SAP CPQ REST API Authentication via JWT token in CPI

0 Likes 49 Views 0 Comments

Introduction –

Since we are aware that SAP CPI does not support OAuth 2.0 with grant-type any other than “Client Credentials”, in this blog we will be learning about fetching bearer token from “grant-type=password” and fetch JWT token from the bearer token and Authenticate a Standard CPQ API.

Design-

In this blog ,we will be creating 2 iflows. 1st for calling standard CPQ API and get the data from CPQ and 2nd iFlow will be called from 1st iFlow to get bearer token and JWT token and authenticate CPQ API in 1st iFlow.

Here We will have 2 blogs explaining each iFlow in details.

Token Concept-

To get the Bearer token, we make a call to CPQ token API from postman app with grant type=password,

Username, password and Domain=”xyzCPQdev/test/prod”(this value is company and environment specific) and content type is ‘x-www-form-urlencoded’.

token1.jpg

token2.jpg

When we get the bearer token ,We make a call to JWT token URL and provide previously received Bearer token as authentication method and send a GET method to get JWT token in return.

token3.jpg

IFLOW2-

In this IFlow ,we will fetch Bearer token with “Grant-type=password” and then JWT with the help of Bearer token.

Here we will be making a call to this iflow from our Main iflow via ProcessDirect Adapter.

1-2.jpg

In Content Modifier 001 we will be sending data to Token URL and defining the payload

When we post the form, the payload for “ x-www-form-urlencoded “looks like below:

username=abcd&password=abcdef and same we will be using in Content Modifier

2-2.jpg

in Request-Reply 1, we will make Get call to token API, since we have already provided credentials in Body, no need to pass again in HTTP adapter:

3-1.jpg

In Content Modifier 002 we will be saving the response  received from Token URL call.

4-3.jpg

Then in Groovy script 1 we are simply adding Root node to JSON response.(same script used in 1st blog).

Then using JSON to XML converted to get the xml.

Then in Content Modifier 003, saving the access token.

5-2.jpg

In Content Modifier 004 we are creating Authorization header with word “Bearer” and token received from last call.

6-2.jpg

In Request reply 2 ,we are making call to fetch JWT token

7-2.jpg

In Content Modifier 005 ,we are saving the response received

8-1.jpg

Then in Groovy script 2, adding the root to Json received as response before converting to XML and then using JSONtoXML converted to get XML before sending it back to main iflow.

9.jpg

With this design, out iflow 2 is completed and we get JWT token from Bearer token .

Link for blog 1(iflow1)- SAP CPI – Calling CPQ REST API in CPI and fetch the data from CPQ

Thank you so much for reading the blog.

Any comments are most welcome.

Thanks and Regards,

Pooja Tiwari


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK