Before anyone points that this question is repetitive, I would like to mention that I have tried possible solutions given in other similar questions like Change Application Permissions to Allow access to your unique identifier or change IP Relaxation to Relax IP restrictions or to use org specific URL instead of http://test.salesforce.com or http://login.salesforce.com.

I'm trying to implement OAuth in my angular application using jsforce and the first thing I do is create OAuth

let oauth2 = new jsforce.OAuth2({
      loginUrl : this.originUrl,
      clientId : '<client_id>',
      clientSecret : '<client_secret>',
      redirectUri : "<same_as_connected_app>"

Then establishing connectionusing the OAuth object formed in the prior step and call Authorize on connection like mentioned in the jsforce document.

let connection = new jsforce.Connection({ oauth2 });
// Note code I'm getting from redirect url
connection.authorize(code, function(err, userInfo) {
       console.log('RS err', err);
       console.log('RS userInfo', userInfo);

Tried in postman as well getting an error. Attaching screenshot. Code fails at connection.authorize step

enter image description here

  • The example that is provided in documentation for the Web Server OAuth 2.0 flow (which you appear to be using) uses a GET request (with the parameters included in the URL query string) instead of a POST request (which generally includes the parameters in the body of the HTTP request). If you need interactive authentication (i.e. requires the user to input their credentials, which is most of the OAuth flows), then Postman is not the right tool for the job (you'd want to use your internet browser to submit the initial request).
    – Derek F
    Jun 20, 2021 at 17:49
  • If you want to avoid interactive authentication, then you'd want to use the JWT Bearer flow, which involves using a certificate (which can be self-signed) as part of the "digital signature" process.
    – Derek F
    Jun 20, 2021 at 17:50
  • Any examples if you can share using jsforce@Derek? Jun 21, 2021 at 12:10

1 Answer 1


1. First Make sure you have the right URLs

The OAuth token endpoint for Sandbox has to be https://test.salesforce.com/services/oauth2/token

The endpoint for Production or Developer org needs to be https://login.salesforce.com/services/oauth2/token

2. Make sure to use the right parameters

In your postman make sure to not use the login URL parameter. The login URL parameter is not needed to obtain the tokens.

3. The Error is misleading

After some more analysis, the error is misleading a bit. The error message from Salesforce should improve, the reason you see this particular error is because without the right content-type being set, the server can't decode the form values, and so it thinks the first parameter it checks isn't set.

So also make sure you set the content- type to application/x-www-form-urlencoded

  • Hi @Mohit, I did try this, I'm getting invalid_grant invalid authorization code error Jun 21, 2021 at 2:22
  • @Rohan Shenoy Can you share the screenshot of the error with correct parameters. I would also use browser to obtain code and then use code to obtain access token. Jun 21, 2021 at 2:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .