{"id":731,"date":"2020-07-14T10:10:00","date_gmt":"2020-07-14T10:10:00","guid":{"rendered":"https:\/\/www.dhruvsoft.com\/blog\/?p=731"},"modified":"2025-06-09T15:05:23","modified_gmt":"2025-06-09T09:35:23","slug":"salesforce-authentication-using-oauth","status":"publish","type":"post","link":"https:\/\/www.dhruvsoft.com\/blog\/salesforce-authentication-using-oauth\/","title":{"rendered":"Salesforce Authentication using OAuth"},"content":{"rendered":"\n<p>In this article we are providing the Step by Step Guide for Salesforce Authentication using OAuth and integrating Salesforce with any application using REST API.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"417\" src=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2020\/07\/Salesforce-Authentication-using-OAuth.jpg\" alt=\"Salesforce Authentication using OAuth\" class=\"wp-image-738\" title=\"Salesforce Authentication using OAuth\" srcset=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2020\/07\/Salesforce-Authentication-using-OAuth.jpg 1000w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2020\/07\/Salesforce-Authentication-using-OAuth-300x125.jpg 300w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2020\/07\/Salesforce-Authentication-using-OAuth-768x320.jpg 768w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/figure>\n\n\n\n<!--more-->\n\n\n\n<p>A CRM application like Salesforce.com helps you to achieve business goals, improve relationships with customers, sales, productivity. Salesforce.com is a CRM (Customer Relationship Management) solution that brings companies and customers together. Over 150,000 companies use Salesforce worldwide. <em>Integration your application with Salesforce <\/em>makes a great sense &#8211; as it will increase the reach of your application.<\/p>\n\n\n\n<p>By integrating with Salesforce, organizations can experience greater operational productivity with the data available in real-time. Salesforce offers secure authentications like the traditional way (username\/password), SAML, OAuth, single sign-on (SSO), and OpenID Connect.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Business Scenario<\/h3>\n\n\n\n<p>Let us assume that you have a web\/mobile-based application. You are trying to integrate your application with Salesforce and want to use Salesforce REST API resources. You might be looking for possible ways to authenticate with Salesforce.<\/p>\n\n\n\n<p>For a client application to access REST API resources, the request must be authorized. For this, we need to use the connected app (which is a framework that allows external applications to integrate with Salesforce using APIs) and an OAuth 2.0 authorization flow.&nbsp;<\/p>\n\n\n\n<p>In this article, let&#8217;s discuss how to create a connected app and use OAuth 2.0 authentication.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">&nbsp;Creating a connected app<\/h3>\n\n\n\n<ol class=\"wp-block-list\"><li>From Setup, enter Apps in the Quick Find box, and select App Manager.<\/li><li>Click New Connected App.<\/li><li>Enter the connected app\u00e2\u20ac&#x2122;s name and enter the API name (re-check the name before saving. It can&#8217;t be modified later)<\/li><li>In the API (Enable OAuth Settings) area of the page, select Enable OAuth Settings.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"638\" height=\"129\" src=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2020\/07\/Enable-OAuth-Settings.jpg\" alt=\"\" class=\"wp-image-732\" srcset=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2020\/07\/Enable-OAuth-Settings.jpg 638w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2020\/07\/Enable-OAuth-Settings-300x61.jpg 300w\" sizes=\"auto, (max-width: 638px) 100vw, 638px\" \/><\/figure>\n\n\n\n<ol start=\"5\">\n<li>Enter the callback URL (endpoint) that Salesforce will use to call back to your application during OAuth.<\/li>\n<li>Select the OAuth scopes to apply to the connected<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"650\" height=\"101\" src=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2020\/07\/Select-the-OAuth-scopes.jpg\" alt=\"\" class=\"wp-image-733\" srcset=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2020\/07\/Select-the-OAuth-scopes.jpg 650w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2020\/07\/Select-the-OAuth-scopes-300x47.jpg 300w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/figure>\n\n\n\n<ol start=\"7\"><li>When you\u00e2\u20ac&#x2122;ve configured all settings for your connected app, click Save.<\/li><\/ol>\n\n\n\n<p>Once saved, it generates Consumer Key, Consumer Secret. Copy them!<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"632\" height=\"49\" src=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2020\/07\/configured-all-settings.jpg\" alt=\"\" class=\"wp-image-734\" srcset=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2020\/07\/configured-all-settings.jpg 632w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2020\/07\/configured-all-settings-300x23.jpg 300w\" sizes=\"auto, (max-width: 632px) 100vw, 632px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Request an Access Token<\/h3>\n\n\n\n<p>We need to follow two steps for fetching access token:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><strong>Fetching authorization code<\/strong><\/li><\/ol>\n\n\n\n<p>To get authorization code, we need to make a HTTP request to this endpoint<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>https:&#47;&#47;login.salesforce.com\/services\/oauth2\/authorize?\nclient_id={consumer_key}&amp;\nredirect_uri={callback_url}&amp;\nresponse_type=code<\/code><\/pre>\n\n\n\n<p>Include these parameters in an authorization code request:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>client_id: The connected app\u00e2\u20ac&#x2122;s consumer key\nredirect_uri: same as connected app\u00e2\u20ac&#x2122;s callback URL.<\/code><\/pre>\n\n\n\n<p>After successfully authenticating the user and granting access to the app, Salesforce redirects users to the callback URL with an authorization code.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"649\" height=\"83\" src=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2020\/07\/authorization-code.jpg\" alt=\"\" class=\"wp-image-735\" srcset=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2020\/07\/authorization-code.jpg 649w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2020\/07\/authorization-code-300x38.jpg 300w\" sizes=\"auto, (max-width: 649px) 100vw, 649px\" \/><\/figure>\n\n\n\n<ol start=\"2\"><li><strong>Use authorization code to get token<\/strong><\/li><\/ol>\n\n\n\n<p>To get access token, pass the authorization code to the Salesforce token endpoint as an HTTP POST.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>https:&#47;&#47;login.salesforce.com\/services\/oauth2\/token?grant_type=authorization_code&amp;\ncode={authorization_code}&amp;\nclient_id={consumer_key}&amp;\nclient_secret={consumer_secret}&amp;\nredirect_uri={callback_url}<\/code><\/pre>\n\n\n\n<p>Include these parameters in request:<\/p>\n\n\n\n<p>client_id: The connected app\u00e2\u20ac&#x2122;s consumer key<\/p>\n\n\n\n<p>client_secret: The connected app\u00e2\u20ac&#x2122;s consumer secret<\/p>\n\n\n\n<p>redirect_uri: same as connected app\u00e2\u20ac&#x2122;s callback URL.<\/p>\n\n\n\n<p>After Salesforce validates the connected app\u00e2\u20ac&#x2122;s credentials, it sends back the access token to call back URL in JSON format.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"643\" height=\"244\" src=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2020\/07\/URL-in-JSON-format.jpg\" alt=\"\" class=\"wp-image-736\" srcset=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2020\/07\/URL-in-JSON-format.jpg 643w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2020\/07\/URL-in-JSON-format-300x114.jpg 300w\" sizes=\"auto, (max-width: 643px) 100vw, 643px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Sample API call using Access token<\/h3>\n\n\n\n<p>Let\u00e2\u20ac&#x2122;s fetch the Account object records using the HTTP GET request<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>URL: https:\/\/{instance_url}\/services\/data\/v41.0\/query?q=SELECT+Id+,+Name+from+Account\nHeaders: Authorization: Bearer {access_token}<\/code><\/pre>\n\n\n\n<p>Include these parameters in request<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>instance_url: Salesforce Instance URL (ex: https:\/\/mycompany.salesforce.com)\naccess_token: Salesforce Access token<\/code><\/pre>\n\n\n\n<p>With a successful query, you should receive a response like this one:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"678\" height=\"364\" src=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2020\/07\/API-call-using-Access-token.jpg\" alt=\"\" class=\"wp-image-737\" srcset=\"https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2020\/07\/API-call-using-Access-token.jpg 678w, https:\/\/www.dhruvsoft.com\/blog\/wp-content\/uploads\/2020\/07\/API-call-using-Access-token-300x161.jpg 300w\" sizes=\"auto, (max-width: 678px) 100vw, 678px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p>OAuth integration with Salesforce.com offers a wide range of possibilities and can help you in meeting your business goals. It is simple, secure and easy to implement.<\/p>\n\n\n\n<p>If you are planning to integrate your application with Salesforce.com you can check our <a href=\"https:\/\/www.dhruvsoft.com\/salesforce-com-integration-services\/\">Salesforce.com Integration Services<\/a>. Get in touch with our team of expert integration developers by <a href=\"https:\/\/www.dhruvsoft.com\/contact-us\/\">contacting us<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article we are providing the Step by Step Guide for Salesforce Authentication using OAuth and integrating Salesforce with any application using REST API.<\/p>\n","protected":false},"author":25,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[119],"tags":[],"class_list":["post-731","post","type-post","status-publish","format-standard","hentry","category-integration","entry"],"_links":{"self":[{"href":"https:\/\/www.dhruvsoft.com\/blog\/wp-json\/wp\/v2\/posts\/731","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dhruvsoft.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dhruvsoft.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dhruvsoft.com\/blog\/wp-json\/wp\/v2\/users\/25"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dhruvsoft.com\/blog\/wp-json\/wp\/v2\/comments?post=731"}],"version-history":[{"count":0,"href":"https:\/\/www.dhruvsoft.com\/blog\/wp-json\/wp\/v2\/posts\/731\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dhruvsoft.com\/blog\/wp-json\/wp\/v2\/media?parent=731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dhruvsoft.com\/blog\/wp-json\/wp\/v2\/categories?post=731"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dhruvsoft.com\/blog\/wp-json\/wp\/v2\/tags?post=731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}