How to fix Google OAuth refresh tokens expiring after 7 days
Google OAuth refresh tokens expire after 7 days in Testing. Why publishing a Gmail app is hard, and how to give users Gmail access without owning one.
7 min read

A Gmail agent that works for exactly one week has usually hit the same rule.
Every user signs in, the agent reads their inbox, and seven days later the refresh tokens stop working. Nothing in the code changed. The cause sits in the Google Cloud console: an OAuth app still set to Testing.
The obvious fix is to publish the app. For Gmail, that is where the real work starts.
The more useful fix is structural. An agent does not need its own Gmail OAuth app to give users Gmail access.
Here’s why the Google OAuth refresh token expires, what publishing really involves, and how to connect Gmail through Agent200 instead.
Why the tokens expire
The 7-day rule
Google’s OAuth documentation states the rule plainly. A project with an external user type and a publishing status of Testing “is issued a refresh token expiring in 7 days.”
There is one exception. Apps that request nothing beyond name, email address and basic profile are exempt.
A Gmail agent never qualifies. Reading mail needs Gmail scopes, and those sit well outside the exemption.
Testing has a second limit. Google’s audience settings cap a Testing project at 100 test users, each one listed on the consent screen.
Both limits make sense for what Testing is. Google’s verification exceptions say apps in development, testing or staging are not subject to verification. The 7-day expiry is the price of skipping it.
It also explains the timing. A demo with three test users runs fine for days, long enough to look finished, and then the tokens start dying one by one, each a week after that user signed in.
How can a team confirm that’s the cause? Open the app’s audience settings in the Google Cloud console. If the user type is External and the publishing status is Testing, the expiry is working as designed.
Why publishing doesn’t end it
Moving the app to production removes the Testing rule. It also starts verification.
Gmail’s scope list marks the scopes an inbox agent needs as Restricted. That includes gmail.readonly, gmail.modify and gmail.metadata. Outside the add-on scopes, only gmail.labels is non-sensitive, and labels alone answer nothing.
Could the agent ask for less? Only up to a point. gmail.send is Sensitive rather than Restricted, so a send-only agent still needs verification, but not the security assessment. Anything that reads the inbox lands back on the Restricted list.
Google’s restricted scope rules are blunt: an app that requests sensitive or restricted scopes has to complete verification unless an exception applies, and an app that stores or transmits restricted scope data on servers also has to complete a security assessment.
For restricted scopes, that process goes further than a form. The app needs a privacy policy that meets Google’s verification requirements and a demonstration video of the app. The security assessment is done by a Google-approved third party and repeated at least every 12 months. Google says the whole process can take several weeks.
The app is not idle while it waits. According to Google’s verification FAQ, an app that uses unapproved scopes shows users the unverified app screen and stays under a 100-user cap.
None of this is unreasonable. gmail.readonly reads every message in the account, and Google is right to be strict about who holds that.
The question is who should carry it. Either every agent team runs its own Gmail OAuth app, with the consent screen, the verification and the yearly assessment, or the agent connects through an integration somebody else runs.
Your own OAuth app vs a managed integration
The difference is ownership, so it is worth being exact about it.
With a team’s own app, the OAuth client, the callback and every user’s tokens belong to that team, along with the consent screen and everything Google asks of it.
With Agent200, the Gmail connector page describes a different split: “Agent200 runs the OAuth flow, handles the callback, stores the tokens and refreshes them.” Its FAQ is shorter: “You do not build or maintain an OAuth integration for Gmail.”
That’s the whole distinction. An OAuth app is something a team operates. A managed integration is something it calls.
| Your own Gmail OAuth app | Agent200’s managed integration | |
|---|---|---|
| OAuth flow and callback | Built and hosted by your team | Run by Agent200 |
| Users’ tokens | Stored and refreshed by your code | Stored and refreshed by Agent200 |
| What your app holds | Client ID, client secret and every user’s tokens | One Agent200 API key |
| What the user sees | Your consent screen, under your own verification status | Google’s sign-in page, approved once |
| How a user removes access | Google Account linked apps page | Google Account linked apps page |
That last row matters. Agent200 does not change Google’s rules. It changes whose OAuth app those rules apply to.
How to connect Gmail through Agent200
The Gmail connector takes three calls. Turn Gmail on for the project in the dashboard first, since one key covers every connector enabled there.
1. Create the client with one key.
// Conceptual example
// One Agent200 API key covers every connector enabled for the project.
const agent200 = new Agent200({
apiKey: process.env.AGENT200_API_KEY,
});
2. Connect each user.
// Conceptual example
// Each end user authorizes their own Gmail account, once.
const connection = await agent200
.user("user_123")
.connect("gmail");
if (connection.authorizationUrl) {
// Show this link to your user; Agent200 handles the rest.
console.log(connection.authorizationUrl);
}
The user signs in on Google’s own page and approves access once. The scopes are listed on that authorization screen.
That one connect() call stands in for the parts of an OAuth integration a team would otherwise build and maintain: the redirect route, the code exchange, the token table and the refresh job.
3. Run a request.
// Conceptual example
const result = await agent200
.user("user_123")
.run({
model: "openai/gpt-5.6-sol",
input: "What did the finance team send me this week?",
tools: ["gmail"],
});
console.log(result.output);
Inside run(), Agent200 invokes the model and executes the tool calls it makes, then returns the finished answer. That is the SDK route. MCP vs SDK compares it with connecting an AI client through MCP.
Nowhere in that code is a client secret, a redirect URI or a refresh token. Nor does it mention a consent screen or a publishing status.
Moving an existing agent across takes one more step. A refresh token is issued to one OAuth client, and RFC 6749 has the server check that it is presented by that same client. So each user approves once more through Agent200. After that, the old client secret, the token table and the refresh job can be retired.
What Google can still revoke
Managed OAuth does not overrule Google. Its list of reasons a refresh token stops working applies to every connection, whoever holds the token:
- The user removes the app’s access in their Google Account.
- The user changes their password, and the token includes Gmail scopes.
- The token goes unused for six months.
- A Workspace admin sets a service the app’s scopes depend on to Restricted.
- The account reaches Google’s limit of 100 refresh tokens for one OAuth client, and Google invalidates the oldest.
The Gmail connector page says as much about the first one: “Users can remove the app later in their Google Account, on the linked apps page.”
Agent200’s Security page is careful on the same point: “Tokens are refreshed where the provider supports it.” A refresh cannot bring back a token Google has revoked.
Only the account owner can approve access again. The Security page says private data is reachable only after the person who owns the account has approved the connection, and that when authorization is missing, Agent200 returns an authorization-required response with a URL to show the user.
Build the app to show that link whenever it appears, not only at sign-up. A user who changed their password last night should see one link this morning, not a broken agent.
When your own OAuth app is still the right call
Two cases still favor owning the app.
The first is an internal tool. If every user sits in one Google Workspace organization, the app can use the Internal user type. Google’s production overview says verification is not required for Internal apps, and the 7-day rule only names external ones.
There’s a catch. Internal apps and their users are subject to the organization’s admin policies, which can override standard OAuth behavior for every user in it.
The second is a team that already passed restricted-scope verification. That team has paid the cost, and adding an agent to an approved app is a much smaller job.
Everyone else is weighing the same trade: weeks of verification and a yearly assessment, against not owning the Gmail OAuth app at all.
The token was never the problem
The 7-day expiry looks like a token bug. It is really a question about who owns the OAuth app. Testing mode just asks it early, a week in, instead of at verification.
Answer it once, and refreshing tokens stops being the agent team’s job. Reconnecting still belongs to the user.
The Gmail connector lists the tools an agent gets, and Email and calendar lists the connectors beside it. For what to do with the inbox once it’s connected, see How to build an email agent that gets the answer right. For what happens inside the call, see Inside run().
Google still gets the last word. It always did.


