OAuth2 Client Credentials in SAP CPI

SAP CPI Auth2 tutorial
SAP Tech

OAuth2 Client Credentials in SAP CPI

Overview

SAP CPI provides various APIs out of the box which can be accessed from Integration Flows to perform a variety of operations. For Example, MessageProcessingLogs is an out-of-the-box OData API provided by SAP that gives access to MPL data of Cloud Integration Tenant. This article shows how to access MessageProcessingLogs Odata API using OAuth2 Client Credentials. The data fetched can further be used to automate alert emails, generate reports, and many other real-life scenarios as per requirement.

Pre-requisites

  • An active SAP BTP account with a subscription to the Integration suite. Follow this blog to create a trail account for free.
  • The roles AuthGroup_Adminisrator, AuthGroup_BusinessExpert, and AuthGroup_IntegrationDeveloper are assigned to the user.

Create Service Instance and Service Key

Step 1: Create a Service Instance of Type API and include Role “MonitoringDataRead“. Check this article to create Service Instance. The Only two differences from the above-linked post would be,

  • A plan under Step 2 will now be API.
Plan api
  • Add “MonitoringDataRead” under roles in Step 3. This role is specific to the “MessageProcessingLogs” API. Other APIs might require different roles.
MonitoringDataRead

Step 2: Create a Service Key for the above-created Instance and Note down the clientid, clientsecret, and Tokenurl.

Creating Security Material

Step 1: Navigate to the Overview Page of CPI. Under Manage Security, choose the Security Material tile.

Manage security

Step 2: Click on Create and from the dropdown, select OAuth2 Client Credentials.

OAuth2 Client Credentials

Step 3: Give a meaningful name.

Enter Tokenurl, client id, and client secret obtained in Step 2 against respective fields.

Client Authentication: Send As Request Header

Check Include Scope.

Scope: If you have scopes, enter the same. If none, enter a blank space. (entering blank space is very important. Else it will throw an error. )

Content-Type : application/x-www-form-urlencoded.

Click on Deploy.

OAuth2 Credentials

Using OAuth2 Client Credentials in I-Flow

Step 1 : Create a simple Integration flow as shown below with just a Request Reply step using OData adapter.

iflow

Step 2: Configure OData Adapter as per the requirement.

Authentication : OAuth2 Client Credentials.

Credential Name: Name given to the deployed credential in Step 3 of the previous section. ( CPIOAuth )

OData Connection

In the Processing tab, configure as shown below. Additionally, you can add queries as per requirement.

OData Processing

Step 3: Save and Deploy the Integration Flow.

Step 4: Monitor the Integration Flow in Trace Mode to Check the Output. It will look something as below. The output will have MPL data which can further be used to create working scenarios.

Monitoring

Final Verdict :

In conclusion, The Article shows the working with OAuth Client Credentials to access APIs from SAP CPI.

I hope you enjoyed reading this article on “OAuth Client Credentials in SAP CPI”, If yes, then don’t forget to spread the word about it. Do send the feedback to know more about it. Signing off sudarshanpatwardhan@gmail.com

Tagged , , , , , , ,
Back To Top