How to Authenticate user in Salesforce Using REST Api?<\/strong><\/p>\n Salesforce uses oAuth protocol to allow application users to access the data in salesforce securely without exposing Username and password of a particular user.<\/p>\n <\/p>\n But before we could make a REST Api call, we need to authenticate our app with salesforce, by making it a connected app. To make an App as connected app follow the steps given in this post<\/a>.<\/p>\n There are several OAuth endpoints provided by Salesforce, depending upon our requirement and resources we need to choose an authentication flow from the below<\/p>\n Once we have successfully authenticated our connected app user, salesforce provide us with an access token, which are further utilised to make authenticated REST Api calls.<\/p>\n In this post we are going to discuss the Web Server Authentication Flow<\/strong>.<\/p>\n This authentication flow is used by the application which are hosted over a secure server. In this flow client application redirects the user to another web server i.e. an authorization server where the user get generates an authorize code, now this authorise code is used to fetch the access token from the Salesforce, see the flow diagram below.<\/p>\n Step wise breakdown of the authentication flow:<\/p>\n Parameter\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Description<\/p>\n response_type Must be code for this authentication flow.<\/p>\n client_id\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 The Consumer Key from the connected app definition.<\/p>\n redirect_uri\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 The Callback URL from the connected app definition.<\/p>\n Example authorization url will look something like this:<\/p>\n https:\/\/login.salesforce.com\/services\/oauth2\/authorize?response_type=code<\/p>\n &client_id=3MVG9lKcPoNINVBIPJjdw1J9LLM82HnFVVX19KY1uA5mu0QqEWhqKpoW3svG3X<\/p>\n HrXDiCQjK1mdgAvhCscA9GE&redirect_uri=https%3A%2F%2Fwww.mysite.com%2F<\/p>\n code_callback.jsp&state=mystate<\/p>\n Parameters\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Description<\/p>\n code\u00a0\u00a0\u00a0\u00a0\u00a0 Authorization code the consumer must use to obtain the access and refresh tokens.<\/p>\n state\u00a0\u00a0\u00a0\u00a0\u00a0 The state value that was passed in as part of the initial request, if applicable.<\/p>\n E.g.<\/p>\n https:\/\/www.mysite.com\/authcode_callback?code=aWekysIEeqM9PiT<\/p>\n hEfm0Cnr6MoLIfwWyRJcqOqHdF8f9INokharAS09ia7UNP6RiVScerfhc4w%3D%3D<\/p>\n End point: https:\/\/login.salesforce.com\/services\/oauth2\/token<\/p>\n Parameter\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Description<\/p>\n grant_type\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Value must be authorization_code for this flow.<\/p>\n client_secret\u00a0\u00a0\u00a0\u00a0\u00a0 The Consumer Secret from the connected app definition.<\/p>\n client_id\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 The Consumer Key from the connected app definition.<\/p>\n redirect_uri\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 The Callback URL from the connected app definition.<\/p>\n code\u00a0\u00a0\u00a0\u00a0\u00a0 Authorization code the consumer must use to obtain the access and refresh tokens<\/p>\n E.g.<\/p>\n POST \/services\/oauth2\/token HTTP\/1.1<\/p>\n Host: login.salesforce.com<\/p>\n grant_type=authorization_code&code=aPrxsmIEeqM9PiQroGEWx1UiMQd95_5JUZ<\/p>\n VEhsOFhS8EVvbfYBBJli2W5fn3zbo.8hojaNW_1g%3D%3D&client_id=3MVG9lKcPoNI<\/p>\n NVBIPJjdw1J9LLM82HnFVVX19KY1uA5mu0QqEWhqKpoW3svG3XHrXDiCQjK1mdgAvhCs<\/p>\n cA9GE&client_secret=1955279925675241571&<\/p>\n redirect_uri=https%3A%2F%2Fwww.mysite.com%2Fcode_callback.jsp<\/p>\n Parameters\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Description<\/p>\n access_token\u00a0\u00a0\u00a0 Access token that acts as a session ID that the application uses for making requests. This token should be protected as though it were user credentials.<\/p>\n refresh_token\u00a0 Token that can be used in the future to obtain new access tokens.<\/p>\n instance_url\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Identifies the Salesforce instance to which API calls should be sent.<\/p>\n id\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Identity URL that can be used to both identify the user as well as query for more information about the user. Can be used in an HTTP request to get more information about the end user.<\/p>\n E.g. of the Raw JSON response<\/p>\n {“id”:”https:\/\/login.salesforce.com\/id\/00Dx0000000BV7z\/005x00000012Q9P”,<\/p>\n “issued_at”:”1278448101416″,<\/p>\n “refresh_token”:”5Aep8614iLM.Dq661ePDmPEgaAW9Oh_L3JKkDpB4xReb54_<\/p>\n pZebnUG0h6Sb4KUVDpNtWEofWM39yg==”,<\/p>\n “instance_url”:”https:\/\/***yourInstance***.salesforce.com\/”,<\/p>\n “signature”:”CMJ4l+CCaPQiKjoOEwEig9H4wqhpuLSk4J2urAe+fVg=”,<\/p>\n “access_token”:”00Dx0000000BV7z!AR8AQP0jITN80ESEsj5EbaZTFG0R<\/p>\n NBaT1cyWk7TrqoDjoNIWQ2ME_sTZzBjfmOE6zMHq6y8PIW4eWze9JksNEkWUl.Cju7m4″}<\/p>\n This is the web server Authentication Flow used by Salesforce<\/p>\n Further we will discuss about the other two authentication flow.<\/p>\n How to Authenticate user in Salesforce Using REST Api? Salesforce uses oAuth protocol to allow application users to access the data in salesforce securely without exposing Username and password of a particular user. But before we could make a REST Api call, we need to authenticate our app with salesforce, by making it a connected … \n
\n
\n
\n
\n
\n
Also, Have a look at the below resources:<\/strong><\/h1>\n
\n
Best Salesforce Interview Questions book with Apex and Visualforce concept explained<\/a><\/h3>\n<\/li>\n<\/ol>\n
Also, Have a look at the below learning resources:<\/strong><\/h1>\n
\n
SOQL (Salesforce Object Query Language)<\/a><\/strong><\/em><\/h3>\n<\/li>\n
Apex Trigger Best Practices and the Trigger Framework<\/a><\/strong><\/em><\/h3>\n<\/li>\n
Salesforce Interview Question and Answers Part 2<\/a><\/strong><\/em><\/h3>\n<\/li>\n
Salesforce Interview Questions on Test Class<\/a><\/strong><\/em><\/h3>\n<\/li>\n
Salesforce-lightning-interview-questions-2018<\/cite><\/span><\/a><\/strong><\/em><\/h3>\n<\/li>\n<\/ol>\n
\u00a0 \u00a0 \u00a06.\u00a0Salesforce Interview Questions Batch Class\u00a0<\/a><\/strong><\/em><\/h3>\n","protected":false},"excerpt":{"rendered":"
Continue reading How to Authenticate user in Salesforce Using REST Api?<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":1257,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[178],"tags":[195,196,198,211,210,212,201,203,202,204,206,207,205,208,209,200,199,197],"class_list":["post-1251","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-how-to-do-in-salesforce","tag-how-to-authenticate-user-in-salesforce-using-rest-api","tag-how-to-create-authenticated-website-user-in-salesforce","tag-oauth-web-server-flow-salesforce","tag-salesforce-authorization-bearer-token","tag-salesforce-authorization-endpoint","tag-salesforce-authorization-url","tag-salesforce-oauth-authentication","tag-salesforce-oauth-authentication-example","tag-salesforce-oauth-authentication-failure","tag-salesforce-oauth-callback-url","tag-salesforce-oauth-redirect-uri","tag-salesforce-oauth-redirect-url","tag-salesforce-oauth-redirect_uri_mismatch","tag-salesforce-oauth-rest-api","tag-salesforce-rest-oauth-token","tag-salesforce-trusted-ip-range","tag-salesforce-trusted-ip-range-for-oauth-web-server-flow","tag-web-server-flow-salesforce"],"_links":{"self":[{"href":"https:\/\/salesforcenextgen.com\/wp-json\/wp\/v2\/posts\/1251","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/salesforcenextgen.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/salesforcenextgen.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/salesforcenextgen.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/salesforcenextgen.com\/wp-json\/wp\/v2\/comments?post=1251"}],"version-history":[{"count":3,"href":"https:\/\/salesforcenextgen.com\/wp-json\/wp\/v2\/posts\/1251\/revisions"}],"predecessor-version":[{"id":2184,"href":"https:\/\/salesforcenextgen.com\/wp-json\/wp\/v2\/posts\/1251\/revisions\/2184"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/salesforcenextgen.com\/wp-json\/wp\/v2\/media\/1257"}],"wp:attachment":[{"href":"https:\/\/salesforcenextgen.com\/wp-json\/wp\/v2\/media?parent=1251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/salesforcenextgen.com\/wp-json\/wp\/v2\/categories?post=1251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/salesforcenextgen.com\/wp-json\/wp\/v2\/tags?post=1251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}