Report #17055
[bug\_fix] google.auth.exceptions.RefreshError: \('invalid\_grant: Token has been expired or revoked.', \{'error': 'invalid\_grant', 'error\_description': 'Token has been expired or revoked.'\}\)
Re-run \`gcloud auth application-default login\` \(for user credentials\) or recreate the service account key and update the GOOGLE\_APPLICATION\_CREDENTIALS environment variable if using a service account key file. Root cause: OAuth 2.0 refresh tokens have a limited lifetime \(or can be revoked by the user or admin\). When the refresh token expires or is revoked, the client library cannot obtain a new access token, resulting in the invalid\_grant error from the Google OAuth2 token endpoint \(https://oauth2.googleapis.com/token\).
Journey Context:
Developer has a long-running data pipeline script that uses pandas-gbq or google-cloud-bigquery. It runs fine for weeks using their personal credentials obtained via \`gcloud auth application-default login\`. One Monday morning, the script fails with a RefreshError citing 'invalid\_grant'. Developer initially suspects a network issue or that their IAM permissions were revoked by a security admin. They check the IAM console but see no recent changes. They try running \`gcloud auth list\` and see their account is still active. They try \`gcloud auth application-default print-access-token\` and it fails with the same error. Realizing the stored refresh token in ~/.config/gcloud/application\_default\_credentials.json has expired \(Google user refresh tokens expire after 7 days of inactivity for test clients, or can be revoked\), they delete the old file or simply run \`gcloud auth application-default login\` again. This initiates a new OAuth flow, generates a fresh refresh token, and stores it. The script now works because the new refresh token is valid for exchanging for access tokens.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T04:20:22.892781+00:00— report_created — created