{"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 class=\"wp-block-paragraph\">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 class=\"wp-block-paragraph\">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 class=\"wp-block-paragraph\">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<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_83 ez-toc-wrap-left-text counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.dhruvsoft.com\/blog\/salesforce-authentication-using-oauth\/#Business_Scenario\" >Business Scenario<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.dhruvsoft.com\/blog\/salesforce-authentication-using-oauth\/#_Creating_a_connected_app\" >&nbsp;Creating a connected app<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.dhruvsoft.com\/blog\/salesforce-authentication-using-oauth\/#Request_an_Access_Token\" >Request an Access Token<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.dhruvsoft.com\/blog\/salesforce-authentication-using-oauth\/#Sample_API_call_using_Access_token\" >Sample API call using Access token<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.dhruvsoft.com\/blog\/salesforce-authentication-using-oauth\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Business_Scenario\"><\/span>Business Scenario<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">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 class=\"wp-block-paragraph\">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 class=\"wp-block-paragraph\">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\"><span class=\"ez-toc-section\" id=\"_Creating_a_connected_app\"><\/span>&nbsp;Creating a connected app<span class=\"ez-toc-section-end\"><\/span><\/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 class=\"wp-block-paragraph\">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\"><span class=\"ez-toc-section\" id=\"Request_an_Access_Token\"><\/span>Request an Access Token<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">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 class=\"wp-block-paragraph\">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 class=\"wp-block-paragraph\">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 class=\"wp-block-paragraph\">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 class=\"wp-block-paragraph\">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 class=\"wp-block-paragraph\">Include these parameters in request:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">client_id: The connected app\u00e2\u20ac&#x2122;s consumer key<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">client_secret: The connected app\u00e2\u20ac&#x2122;s consumer secret<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">redirect_uri: same as connected app\u00e2\u20ac&#x2122;s callback URL.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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\"><span class=\"ez-toc-section\" id=\"Sample_API_call_using_Access_token\"><\/span>Sample API call using Access token<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">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 class=\"wp-block-paragraph\">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 class=\"wp-block-paragraph\">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\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">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 class=\"wp-block-paragraph\">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}]}}