invalid_grant: meaning and how to fix it

Integration and API Checked against the official docs on Source: SOAP API Developer Guide: Core Data Types, StatusCode

Quick answer

invalid_grant: An OAuth token request was refused. Common reasons: wrong username, password or token, a user the connected app does not allow, an expired or revoked refresh token, or a login URL that does not match the org (production versus sandbox or My Domain). Start with: Check the token endpoint host matches the org type (login.salesforce.com, test.salesforce.com or your My Domain).

Typical message: {"error":"invalid_grant","error_description":"authentication failure"}

Cause

An OAuth token request was refused. Common reasons: wrong username, password or token, a user the connected app does not allow, an expired or revoked refresh token, or a login URL that does not match the org (production versus sandbox or My Domain).

How to fix invalid_grant

  1. Check the token endpoint host matches the org type (login.salesforce.com, test.salesforce.com or your My Domain).
  2. Check the connected app policies: permitted users and pre-authorized profiles or permission sets.
  3. For JWT bearer flow, check the username, the certificate and that the app is pre-authorized for that user.
  4. Request a new refresh token if the old one was revoked.

Have a different message? Paste it into the error decoder, which matches it against 45 common Salesforce errors in your browser.

Frequently asked questions

What does invalid_grant mean in Salesforce?

An OAuth token request was refused. Common reasons: wrong username, password or token, a user the connected app does not allow, an expired or revoked refresh token, or a login URL that does not match the org (production versus sandbox or My Domain).

How do I fix invalid_grant?

1. Check the token endpoint host matches the org type (login.salesforce.com, test.salesforce.com or your My Domain). 2. Check the connected app policies: permitted users and pre-authorized profiles or permission sets. 3. For JWT bearer flow, check the username, the certificate and that the app is pre-authorized for that user. 4. Request a new refresh token if the old one was revoked.

More Integration and API errors

SFDX Talk is unofficial documentation. It is not affiliated with, endorsed by, or sponsored by Salesforce, Inc. Message text varies slightly by release and context, so confirm against the official page before relying on it.