+ 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
See if the solution in the below post helps


Also follow the flow explained in the below article
Yuriy BarannikovYuriy Barannikov

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?