JSforce - how to use OAuth2 without redirect user to Salesforce page to get authorized?

1.8k Views Asked by At

I want to use JSforce to connect to Salesforce from node.js backend by using OAuth2 method, but it need to redirect the user to Salesforce page to get authorized. Is it possible to get authorized without user interaction?

I'm following the documentation here

Authorization Request

First, you should redirect user to Salesforce page to get authorized. You can get Salesforce authorization page URL by OAuth2#getAuthorizationUrl(options).

1

There are 1 best solutions below

0
On

OAuth supports multiple flows, suitable for different scenarios:

  1. If you want to connect to a Salesforce instance of one of the users of your application, you would use the OAuth authorization code grant which you referenced in your question. It does require you to take the user of your application through the browser-based authorization flow that redirects to Salesforce and then back to your app. The process ends with your app obtaining an access token to Salesforce APIs which you can use with jsforce. If your app needs to access your user's Salesforce instance over time, during this initial browser-based flow you can also request the issuance of a refresh token. Your app can then use the refresh token at a later time to obtain a fresh access token without requiring further user interaction. Authentication is only one of many challenges to think about when implementing integrations in your app.
  2. If you want to connect to a Salesforce instance you own yourself from within the trust boundary of your middle-tier, the suitable OAuth flow to use is OAuth client credentials grant. In this case, you only need to provide jscforce client with the client ID and client secret of the OAuth client you configured in your Salesforce instance. For jsforce, this is documented here.