Authenticating Salesforce REST API calls to custom Apex endpoints

Posted: December 11, 2015  |  Categories: BizTalk Uncategorized

Seroter has shown us how to call the Force.com REST API from BizTalk Server and we used this to successfully call standard Force.com objects like .salesforce.com/services/data/v34.0/sobjects/contacts”>https://<blah>.salesforce.com/services/data/v34.0/sobjects/contacts. We could not use this to call custom force.com objects like .salesforce.com/services/apex/ContactMapping”>https://<blah>.salesforce.com/services/apex/ContactMapping unless we modified the published WCF Behaviour for authentication. Thanks to Aravindh Kathiresan for working all this out. The purpose of this blog is to share how we modified this behaviour and as a memory dump for me.

We started from code shared by Muhummad Ehsan. The Force.com login endpoint is hard coded to https://login.salesforce.com/services/oauth2/token when calling the REST API authentication service. We had to change this to .salesforce.com/services/oauth2/token”>https://<blah>.salesforce.com/services/oauth2/token . First we changed this line of code in SfdcTokenManager.cs to dynamically assign the Force.com login endpoint.

OAuth1

Secondly we added a new oauthurl configuration property
,OAuth2

and changed the return signatures to

OAuth3

The OAuthURL was added to the struct in the  RestAuthConfiguration.cs.

OAuth4

Finally the SfdcRestAuthBehavior.cs was refactored to include the OAuthURL.

OAuth5

After deploying the modified behaviour an authentication endpoint can be configured on the endpoint behaviour as shown below;

OAuth6

In summary we have shown how to dynamically configure a Salesforce authentication endpoint in a custom endpoint behaviour. This can be used to call a REST API with a custom Apex endpoint.

BizTalk360
BizTalk Server

Over 500+ customers across
30+ countries depend on BizTalk360

Learn More
Serverless360
Azure

Manage and monitor serverless
components effortlessly

Learn More
Atomicscope
Business Users

Monitor your Business Activity in iPaaS
or Hybrid integration solutions

Learn More

Back to Top