Guide
invalid_grant: Google says the token is no longer valid
How this guide was made: Written with AI assistance and checked against the sources linked on this page.
Updated
Short answer: Google returns invalid_grant when your app tries to refresh an access token, or exchange an authorization code, and Google rejects it. The token may have expired or been invalidated, or the code may be invalid or in the wrong format. Google's fix is to authenticate the user again and ask for consent to get new tokens.
What does it mean?
Google's OAuth 2.0 web server page explains the two places this error appears. When refreshing an access token, "the token may have expired or has been invalidated. Authenticate the user again and ask for user consent to obtain new tokens." When exchanging an authorization code, the error reads "The supplied authorization code is invalid or in the wrong format," and the suggested fix is to restart the OAuth process to prompt the user for consent again.
Google's OAuth 2.0 overview says a refresh token "might stop working" for listed reasons, and that "You must write your code to anticipate the possibility that a granted refresh token might no longer work." The causes below follow that list.
Which cause is it?
| What you see | Cause | Fix |
|---|---|---|
| A refresh call fails for a user who signed in some time ago | The refresh token stopped working: revoked, unused for six months, time-based access ended, password changed with Gmail scopes, or a Workspace admin restricted a service | Cause 1 |
| Refresh fails about a week after sign-in, for an app in Testing status | Google issues a refresh token that expires in 7 days for these apps | Cause 2 |
| A user's older token stops working after a new sign-in | The 100 refresh token limit per Google Account per OAuth client ID | Cause 3 |
| The failure happens during the sign-in callback, when the code is exchanged | The authorization code was invalid or in the wrong format | Cause 4 |
| The error response has error_subtype set to invalid_rapt | A session control policy ended the session | Cause 5 |
Cause 1: The refresh token stopped working
Google's refresh token list gives these reasons: the user revoked your app's access; the refresh token has not been used for six months; the user changed passwords and the refresh token contains Gmail scopes; the user account exceeded the maximum number of granted live refresh tokens; the user granted time-based access and it expired; or an admin set a service in your app's scopes to Restricted, which gives the error admin_policy_enforced.
- Log the full error response, including the error_subtype field if present. Google says error_subtype can separate a revoked token from a session control failure.
- Ask the user to sign in again and grant consent. Google's guidance is to "Authenticate the user again and ask for user consent to obtain new tokens."
- Save the new refresh token for that user. Our suggestion: replace the old one in your database or secret store.
- If the same error returns for a user who just consented, follow Google's advice to check that your app is configured correctly and that you use the correct tokens and parameters in your request. Google adds that otherwise "the user account may have been deleted or disabled."
- If the error names admin_policy_enforced, the cause is an admin setting, not your token. Check that case separately, since it is set by the admin.
Cause 2: The app is in Testing status
Google's OAuth overview says that a Google Cloud project with an OAuth consent screen set to the external user type and a publishing status of "Testing" "is issued a refresh token expiring in 7 days." The exception is when the only requested scopes are name, email, and profile scopes.
- Open the OAuth consent screen in Google Cloud and check the publishing status.
- If the status is Testing and your app requests scopes beyond name, email, and profile, expect the refresh token to expire after 7 days.
- When it expires, ask the user to sign in and consent again, as in Cause 1, step 2. Save the new refresh token.
Google's pages that we read do not describe a setting that removes this 7-day limit, so this guide does not give one.
Cause 3: The 100 refresh token limit replaced the old token
Google says there is "a limit of 100 refresh tokens per Google Account per OAuth 2.0 client ID." If the limit is reached, "creating a new refresh token automatically invalidates the oldest refresh token without warning." Service accounts are not subject to this limit.
- Our suggestion: find where your app stores refresh tokens, and check whether a new token is stored for a user each time they sign in without replacing the old one.
- Our suggestion: keep one stored refresh token per user per OAuth client. When a user consents again, replace the stored token with the newest one.
- For each user whose token now returns invalid_grant, ask them to sign in and consent again.
Cause 4: The authorization code was invalid or in the wrong format
Google's token exchange error says: "The supplied authorization code is invalid or in the wrong format." The suggested fix is "Request a new code by restarting the OAuth process to prompt the user for consent again."
- Restart the sign-in flow from your app's sign-in button. Our suggestion: do not reuse a code from an earlier attempt.
- Our suggestion: in the callback, read the code from the redirect URL and send that value to Google's token endpoint without changing it.
- Our suggestion: log the request and the response for the exchange, and check how your server reads the callback.
Cause 5: A session control policy ended the session
For Google Cloud Platform organizations, Google says that a failed call "will fail with an error type invalid_grant," and that "the error_subtype field can be used to distinguish between a revoked token and a failure due to a session control policy (for example, "error_subtype": "invalid_rapt")." Google says session durations "can be very limited (between 1 hour to 24 hours)," so the app must handle this by restarting an auth session.
- Read error_subtype in the response. If it is invalid_rapt, the cause is a session control policy, not a revoked token.
- Restart the auth session when this happens. Google says the scenario "must be handled gracefully by restarting an auth session."
- If the session length is set by a Workspace or Cloud admin, that admin can review it. Google says the session length "set by the admin could have been exceeded."
How do I check it's fixed?
- Run the refresh call that failed. A working refresh returns an access token and no invalid_grant error.
- Sign in again as the affected user and confirm the new refresh token is saved, replacing the old one.
- If the error returns for a user who just consented, re-read the Cause 1 step 4 check on configuration and parameters.
- For an app in Testing status, expect the 7-day limit from Cause 2 and plan for consent again when the token expires.
FAQ
Why did my app work yesterday and fail today?
Google says a refresh token can stop working when it has not been used for six months, when a password changed with Gmail scopes, or when time-based access ran out. It can also stop when the user revoked access. Check which of these applies in the Cause 1 list.
Will signing in again fix invalid_grant?
Google's advice is to authenticate the user again and ask for consent to get new tokens. If the error still appears after a fresh consent, Google says to check that your app's configuration and the tokens and parameters in your request are correct.
Is invalid_grant the same as invalid_client?
No. Google's error list gives invalid_client as "The OAuth client secret is incorrect," and it says to review the client ID and secret used for the request. invalid_grant concerns the token or the code.
Is this the same as the "Access blocked" error?
Not necessarily. Google's account help page says a "400 invalid_request" or "Access blocked" error means the app sent an invalid request, using an authorization method Google does not allow. A 400 admin_policy_enforced error is a different case, covered in its own guide.
Related guides
Sources
- <https://developers.google.com/identity/protocols/oauth2> (refresh token expiration, Testing status, 100-token limit, session control)
- <https://developers.google.com/identity/protocols/oauth2/web-server> (invalid_grant at token exchange and at refresh, invalid_client)
- <https://support.google.com/accounts/answer/16668185?hl=en> (400 invalid_request and Access blocked; 400 admin_policy_enforced)
Last checked: 17 November 2026.
VibeFix is independent. Google is a trademark of Google LLC.
More guides · Shopify store accessibility · About · Your privacy choices