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 

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.

login.salesforce.com/services/oauth2/token

Yuriy BarannikovYuriy Barannikov
Hi, 

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