function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Yuriy BarannikovYuriy Barannikov 

OAuth 2 auth error - invalid_grant

OAuth 2 error - invalid_grant

Hi guys,

Trying to authenticate using OAuth2.
GOT code successfully, but can't get access_token by code. Everytime receives invalid_grant - please see screnshot
What I am doing wrong, please suggest.

invalid grant

To see the screnshot please right-click on it and open in a new window.

Thank you in advance
Ramu_SFDCRamu_SFDC
See if the solution in the below post helps

https://developer.salesforce.com/forums/?id=906F000000099liIAA

Also follow the flow explained in the below article
https://help.salesforce.com/HTViewHelpDoc?id=remoteaccess_oauth_web_server_flow.htm&language=en_US
Yuriy BarannikovYuriy Barannikov
Hi, 

Thank you for the reply.
Unfourtunatelly I had seen both articles you suggested

Regardging the first one:
I use OAuth2 with code and token and my error is not about Password:
{"error_description":"authentication failure","error":"invalid_grant"}

Regarging second one:
IP restrictions set to Relax. IP Relaxation: Relax IP restrictions

Please, any suggestions, I have no idea why it doesn't work.

Once again what I did:
  1. Create account in salesforce
  2. Create New App, get security id and secret to use in my WebApp
  3. Send GET request to https://login.salesforce.com/services/oauth2/authorize?response_type=code&client_id=%s&redirect_uri=%s
  4. The request above redirects me to the login page, when I log in 
  5. Got the code in my app (for example: aPrxh1FYoyyqodpf8DsHwLC9jnfA5HkfzcnY3g2NsmnN3MXY1Vc7kdCE0eB4WzpxxiNQI_vklQ)
  6. Send POST request to https://login.salesforce.com/services/oauth2/token with grant_type, client_id, client_secret, redirect_uri and code form parameters.
  7. Receive HTTP 400 with JSON below:
{"error_description":"authentication failure","error":"invalid_grant"}

Guys, please, tell me what am I doing wrong?

Yuriy