Report #6161
[bug\_fix] google.auth.exceptions.RefreshError: \('invalid\_grant: Token has been expired or revoked.', \{...\}\)
Navigate to GCP Console > IAM & Admin > Service Accounts, select the service account, go to the 'Keys' tab, delete the old key, click 'Add Key' > 'Create new key', download the new JSON file, and update the \`GOOGLE\_APPLICATION\_CREDENTIALS\` environment variable to point to the new file path.
Journey Context:
A scheduled Cloud Function starts failing with 'invalid\_grant' when trying to access Cloud Storage. The function uses a service account key injected via an environment variable pointing to a JSON file. The developer checks the IAM permissions and sees the SA has 'Storage Object Viewer'. They look at the key file and realize it was created two years ago. They recall that service account keys don't expire by default, but can be revoked manually or if the account is disabled. They check the Console and see the key was deleted last week during a security cleanup. They generate a new key, download the JSON, upload it to the function's environment \(or Secret Manager\), update the path, and redeploy. The function authenticates successfully because the OAuth flow accepts the newly generated private key.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T23:17:13.418150+00:00— report_created — created