OAuth 2.0 Error: invalid_grant

The authorization code, refresh token or credentials sent to the token endpoint are invalid, expired, already used or were issued to a different client.

Exact message you may see Token has been expired or revokedBad Request invalid_grantauthorization code expiredMalformed auth code
Seen on: Google Microsoft REST API

Meaning

invalid_grant is returned by the OAuth token endpoint (Google, Microsoft, Auth0, Okta, Salesforce…). The grant — the thing you exchange for tokens — is no longer acceptable. Authorization codes are single-use and short-lived (often 30–60 seconds to 10 minutes); refresh tokens can be revoked or expire.

Common causes

  • Authorization code already used (double submit, page refresh, retries)
  • Authorization code expired before exchange
  • redirect_uri in the token request differs from the one used in the authorize request
  • Refresh token revoked (password change, user removed app access, token limit exceeded)
  • Google: app in “Testing” publishing status — refresh tokens expire after 7 days
  • Server clock skew (JWT client assertions)
  • PKCE code_verifier doesn’t match the code_challenge

⚡ Quick fix

  1. Exchange the code exactly once, immediately after the redirect
  2. Use the byte-identical redirect_uri in both requests
  3. On refresh failure, send the user through login/consent again
  4. For Google apps in testing, publish the app or expect weekly re-consent
  5. Sync server time via NTP

Detailed fix by platform

Google

  1. Check OAuth consent screen publishing status; refresh tokens for “Testing” apps last 7 days. Users can revoke access at myaccount.google.com/permissions.

Microsoft

  1. The error_description contains an AADSTS code (e.g. AADSTS70008 = expired code, AADSTS50173 = grant revoked after password change).

How to diagnose

  1. Grant type — Authorization code or refresh token?
  2. Freshness — Was the code used once, quickly?
  3. redirect_uri — Identical in authorize and token requests?
  4. Revocation — Password change or user revoked consent?
  5. Description — Read error_description for provider-specific codes

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

400 — HTTP 400 Bad Request (HTTP)400401 — HTTP 401 Unauthorized (HTTP)401401 — 401 Unauthorized without WWW-Authenticate header (HTTP)401401 — 401 Bearer error="invalid_token" (HTTP)401403 — 403 Bearer error="insufficient_scope" (HTTP)403AADSTS500113 — AADSTS500113: No reply address is registered for the application (Azure)AADSTS500113AADSTS50076 — Azure AD (Entra ID): AADSTS50076 / AADSTS50079 — multi-factor authentication required (Azure)AADSTS50076AADSTS50126 — AADSTS50126: Error validating credentials due to invalid username or password (Azure)AADSTS50126invalid_g…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.