Integrating/Subscribing SalesForce Platform events in SAP Cloud Platform Integration using JWT OAuth Bearer Flow – Part 2
In Part 1, we have covered “How to create Platform events, Triggers and Connected applications in Salesforce environment”.
In this blog post, we will be focusing on “How can we subscribe to Salesforce Platform events in SAP CPI using ADVANTCO SFDC adapter”.
To subscribe to the events in SAP Cloud platform integration, we will be using the Advantco SFDC adapter. You can find details of the Advantco SFDC adapter on the Advantco website.
Below are some of my experiences working with Advantco SFDC adapter:
- Advantco SFDC is currently not available in CPI tenants on the Cloud Foundry environment, though it is expected to be available by end of July 2020.
- It is available in the Neo environment, but one needs to install the adapter using Eclipse(Oxygen) IDE. Anil Yakkali has written a great blog on how to install Advantco adapter and Workbench.
I have installed the adapter and I can see ADVANTCO-SFO in my Adapter list on SAP CPI as shown below:
Now the requirement is to subscribe to the platform event LeadInfo1(using OAUTH JWT bearer flow) created in Salesforce as shown in Part 1 of the blog post.
Before proceeding further on how to subscribe to the event created, I would like to throw some light on the OAuth JWT Bearer flow.
OAuth 2.0 JWT Bearer Flow for Server to Server Integration
In some of the scenarios, you want to authorize servers to access data without logging every time the servers exchange information. In such cases, you can use the OAuth 2.0 JSON Web Token (JWT) bearer flow.
JWT bearer flow uses a certificate to sign the JWT request (with header and claims) and no other user interaction is required explicitly(except a prior approval from the client application).
To connect to Salesforce using the JWT Bearer flow, I have created a simple Integration flow with Sender as Salesforce connected using the ADVANTCO-SFO adapter as shown below.
In the Salesforce tab of the adapter technical information, we need to provide the connection details as given below:
Authentication Scheme: In my scenario, I have used the JWT Bearer Token flow.
Issuer: The issuer must contain the OAuth client_id or the connected app for which you registered the certificate. We can get the client id from the Consumer Key field in the Connected application as shown below.
Subject: The subject must contain the username of the Salesforce user or the Salesforce community user if implementing for a community.
Audience: The audience identifies the authorization server as an intended audience. The authorization server must verify that it is an intended audience for the token.
In my scenario it is https://login.salesforce.com
Tick the Enable Channel subscription checkbox and enter Replay Id as -1 and Channel name as given in platform event channel details.
This is all we are supposed to do to connect to the Salesforce platform event bus. How simple it is.. No? Well, Thanks to the ADVANTCO SFDC adapter.
I have created a content modifier in the sample iFLow created above to log the body and see the payload received from Salesforce in the Trace mode.
With the above details, I have deployed the iFlow.
We can go to the Monitor tab to see how this iFLow is listening to the event channel with name /events/LeadInfo1__e.
I can see no completed messages in the past one hour.
We can go back to salesforce and let’s change the lead info again as below:
I have changed the first name from value “First name” to value “Gopesh” and Saved the Lead.
Within couple of seconds, I can see my iFlow triggered automatically.
We can see the payload received from Salesforce with the Trace mode on.
This completes the end to end flow from Salesforce to SAP CPI.
Stay Safe and Happy Learning!