Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google token refresh returns "Token has been expired or revoked."

I have a Google OAuth2 client approved by Google, which provides offline access to user's account with required scopes. My backend application stores and uses the refresh token to refresh the access tokens as and when needed.

Lately, we are seeing that our token refresh attempt is met with an error from Google with:

{
    "error" : "invalid_grant",
    "error_description" : "Token has been expired or revoked."
}

There is no additional information.

Nothing has changed in my Google OAuth client. The user has not changed account password. The user has not revoked access to my client.

What could be the reason for suddenly getting such errors for token refresh? And how do I avoid this in future (if possible)?

like image 493
Urjit Avatar asked Aug 14 '18 16:08

Urjit


People also ask

How do I stop Google from revoking my refresh token?

In their "OAuth 2.0 Playground" tool, Google states the following: Note: The OAuth Playground will automatically revoke refresh tokens after 24h. You can avoid this by specifying your own application OAuth credentials using the Configuration panel.

Do Google refresh tokens expire?

The Google Auth server issued Refresh tokens never expire — that's the whole point of the refresh tokens. The refresh token will expire (or I should say become unauthorized) when the user revokes access to your application.

What happens when refresh token expires?

Refresh Token Rotation issues a refresh token that expires after a preset lifetime. After expiration, the user gets a new refresh token in the same family, or refresh tokens that share a family ID, or a new access token/refresh token pair. To learn more, read Refresh Token Rotation.


2 Answers

Are you inadvertently asking for the refresh token multiple times? There is a limit of approx. 25 refresh tokens that an account can have extant.

like image 56
pinoyyid Avatar answered Sep 16 '22 20:09

pinoyyid


I had same issue, because I run my code in 2 different files and what I did remove token.pickle file, re-run it again.

like image 21
Bob Boroujerdi Far Avatar answered Sep 17 '22 20:09

Bob Boroujerdi Far