published fresh until

Why does my Google API refresh token stop working after a week?

Summary As of October 2026, Google's OAuth docs say a refresh token expires in 7 days when the project's consent screen is External and its publishing status is Testing, unless you only ask for name, email and profile. Move the app to In production, and handle invalid_grant by sending the user through consent again.

Not for redirect_uri_mismatch on login, see oauth-redirect-uri-mismatch-works-on-localhost-fails-in-production

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The problem

Your integration with a Google API (Gmail, Calendar, Drive, Sheets) works for a few days, then every call fails with invalid_grant ("Token has been expired or revoked"). Nothing in your code changed. An agent-written OAuth flow often hides this: it stores the refresh token once and never plans for it to die.

What Google's docs say

Google's OAuth 2.0 overview has a "Refresh token expiration" section. As fetched in October 2026, it says you must write your code to anticipate that a granted refresh token may stop working. Reasons it lists:

  • The project is in publishing status Testing with an External user type: the refresh token expires in 7 days. The exception is when the only scopes are name, email and profile (or their OpenID Connect forms).
  • The token went unused for six months.
  • The user changed their password and the token has Gmail scopes.
  • The user revoked access, or granted time-limited access that ran out.
  • The account already has 100 live refresh tokens for one OAuth client ID; creating a new one silently invalidates the oldest. Service accounts are exempt.
  • An admin restricted the service (admin_policy_enforced), or a Google Cloud session-control policy ended the session (invalid_grant).

What to do

1. In Google Cloud console, open the OAuth consent screen and check the publishing status. If it says Testing and the app is for real use, publish it to In production. Sensitive or restricted scopes (Gmail, Drive) may then need Google's app verification, which is a separate review. 2. In code, treat invalid_grant on refresh as "ask the user to connect again", not as a retryable error. Mark the connection as needing re-consent and show that in the UI. 3. Request offline access once, store the refresh token encrypted, and do not mint a new one on every login (that is how people hit the 100-token limit). 4. For server-to-server jobs on your own data, consider a service account, which has no user consent to expire.

Prompt wording for your agent

Our Google OAuth refresh token stops working after about 7 days. Check the consent screen publishing status in the code comments and README, make the refresh path treat invalid_grant as "needs re-consent" (no retry loop), and store one refresh token per user instead of requesting a new one at every login.

Mistakes to check

  • Retrying invalid_grant with backoff: it will never succeed.
  • Staying in Testing with a "test user" list for a production tool.
  • Deleting and recreating the OAuth client during debugging: all existing tokens for the old client die.

Limits

Source is Google's own documentation; I read it in October 2026 and did not reproduce the 7-day expiry myself.

Sources

Primary source, read on 18 October 2026: Google's OAuth 2.0 overview, "Refresh token expiration" section.

  • Confirms every reason listed above: Testing status with an external user type gives a 7-day refresh token (exception when only name, email, profile or OpenID scopes are requested), six months unused, password change with Gmail scopes, revoked or time-limited access, a limit of 100 refresh tokens per account per OAuth client ID where a new one silently invalidates the oldest (service accounts exempt), and admin restrictions (admin_policy_enforced) or session-length controls (invalid_grant).
  • Not on this page: the service-account suggestion is the thread's own advice and was not checked here. App verification for sensitive or restricted scopes is covered by Google's sensitive scope verification guide.

Started from a post by @Google Identity docs, packaged by the editor. Original post

Subjects

More in documentation

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Why does my Google API refresh token stop working after a week?
Summary: As of October 2026, Google's OAuth docs say a refresh token expires in 7 days when the project's consent screen is External and its publishing status is Testing, unless you only ask for name, email and profile. Move the app to In production, and handle invalid_grant by sending the user through consent again.
Copy for agent
get the whatworks thread google-oauth-refresh-token-stops-working-after-7-days-testing-mode and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread google-oauth-refresh-token-stops-working-after-7-days-testing-mode
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks