Google OAuth refresh token expires after 7 days: Testing status
Google refresh tokens die after 7 days when your OAuth app is in Testing and asks for more than basic scopes. Publish it to In production to fix invalid_grant.
Why your Google refresh token stops after 7 days
A Google OAuth refresh token that expires after 7 days almost always means your Google Cloud project has user type External and publishing status Testing. Google issues 7-day refresh tokens to such projects unless the app only asks for name, email and profile. After that week every refresh call fails with invalid_grant. The fix is to publish the app to In production on the Audience page, then have each user sign in once more to get a token that lasts.
What the failure looks like
Nothing breaks on the day you connect. The trouble starts a week later, usually in a background job that calls a Google API while the user is away. The token endpoint answers with an error object instead of a fresh access token. Many libraries wrap it, so search your logs for the error code rather than a full sentence.
Google's web server guide describes invalid_grant on refresh as a token that has expired or been invalidated, and tells you to send the user through consent again. If you use Auth.js and its refresh token rotation pattern, the same failure shows up as RefreshTokenError on the session, because that is the name the guide's example code sets when the refresh request fails.
POST https://oauth2.googleapis.com/token
grant_type=refresh_token&refresh_token=1//0g...
HTTP/1.1 400 Bad Request
{
"error": "invalid_grant",
"error_description": "..."
}
// Auth.js refresh rotation example
session.error === "RefreshTokenError"The rule, in Google's words
Google's OAuth 2.0 overview lists the ways a refresh token can stop working. One line covers this case exactly: a project with an external user type and a publishing status of Testing is issued a refresh token expiring in 7 days. The exception is an app whose only scopes are a subset of name, email address and user profile, meaning openid, userinfo.email and userinfo.profile or their OpenID Connect equivalents.
The Manage App Audience help page says the same from the other side. Authorisations by a test user expire seven days from the time of consent, and if your client asked for offline access, the refresh token expires too. That is why plain Sign in with Google keeps working in Testing for months, while a feature that reads Calendar or Drive dies after a week.
Which apps are affected
| Setup | Refresh token lifetime | What to do |
|---|---|---|
| External, Testing, only openid/email/profile | Not limited to 7 days | Nothing for this rule |
| External, Testing, any other scope (Calendar, Drive, Gmail, Sheets) | 7 days from consent | Publish to In production |
| External, In production | No 7-day limit | Verify if scopes are sensitive or restricted |
| Internal (Workspace organisation only) | No publishing status applies | Nothing for this rule |
| Personal (single creator account) | Not subject to the 7-day test token expiry | Only usable by the account that created it |
A worked example
Take Tallyroom, a scheduling app at tallyroom.app that reads each user's calendar to suggest meeting slots. It runs on Railway and stores refresh tokens in Postgres. The Google project was created during development, left in Testing, and the founder added ten beta users as test users.
For six days everything works. On day eight, the nightly sync job logs invalid_grant for every user who connected in the first batch. Signing out and in again fixes one user for another week. Nothing in the code changed. The project's publishing status did all of it, because calendar.readonly is not one of the basic sign-in scopes.
Fix it step by step
- Open the Google Cloud console, choose the project that owns your OAuth client, and go to Google Auth Platform, then Audience.
- Check User type. If it says External and Publishing status says Testing, this is your cause.
- Before publishing, open Data Access and confirm the scope list matches what your code requests. Remove anything you no longer call.
- Click Publish app and confirm. Google treats the project as In production from that moment.
- Ask every affected user to connect again. A token issued while you were in Testing does not become long-lived when you publish, so it still dies on its original date.
- Make sure the new consent actually returns a refresh token (see the next section), and store it, replacing the old one.
Getting a new refresh token on the second sign-in
Google only returns a refresh token if the authorisation request sets access_type=offline. Its guide also says the user is prompted only the first time your project requests access unless you say otherwise. In practice that means a returning user often gets an access token and no refresh token at all.
There are two ways round it. Add prompt=consent to the request so Google shows consent again and issues a new refresh token. Or have the user remove the app at myaccount.google.com/permissions and connect again, which the Auth.js Google provider page also suggests. For an app that only needs offline access for some users, send prompt=consent only from your "Connect Google Calendar" button, not from the normal sign-in.
// auth.ts (Auth.js v5) - only when you need offline access
import Google from "next-auth/providers/google"
Google({
authorization: {
params: {
access_type: "offline",
prompt: "consent",
response_type: "code",
scope: "openid email profile https://www.googleapis.com/auth/calendar.readonly",
},
},
})What publishing changes, and what it does not
Publishing lifts the 100 test user cap and the 7-day expiry. It does not skip review. If any scope on your consent screen is sensitive or restricted, Google shows the unverified app screen until verification for those scopes is complete. Google also caps an app that shows that screen at 100 new users over the lifetime of the project, and the cap cannot be reset.
So the order matters for a launch. Publish early, so tokens stop expiring for your beta users. Start verification at the same time if you need sensitive scopes, and keep the user count below the cap until it is approved. Verification has its own checklist and lead time, so plan for it rather than assume it is quick.
Other reasons refresh tokens fail
If the project is already In production and you still see invalid_grant, work through the rest of Google's list. Each cause looks the same in your logs, so check them in this order.
- The user revoked access in their Google Account settings.
- The refresh token has not been used for six months.
- The user changed their password and the token includes Gmail scopes.
- Too many tokens: Google allows 100 refresh tokens per Google Account per OAuth client ID. A new one silently invalidates the oldest. Developers who reconnect their own account during testing hit this first.
- The user granted time-based access and it ran out.
- A Workspace admin restricted one of your scopes, which returns
admin_policy_enforced, or a Google Cloud session control policy expired, which shows up witherror_subtypeset toinvalid_rapt.
How to confirm the fix
Reload the Audience page and check that Publishing status reads In production. Then connect a fresh account, ideally one that was never a test user, and look at the token response. It should include refresh_token. Note the date, and run your background job against that account eight days later. If it still refreshes, the 7-day rule no longer applies to you.
Add a check in code too. When a refresh fails with invalid_grant, mark the connection as broken and show the user a reconnect button. Google's documentation says to expect that a refresh token may stop working at any time, so this handler is worth having even after the fix.
Prevent it next time
Treat publishing status as part of launch, not an afterthought. Keep separate OAuth clients for development and production if you like, but put the production client in a project you publish before real users connect. Write the scopes you request in one place in your code, and compare that list with Data Access whenever it changes.
The Google account settings sit outside your repository, which is why AI coding agents miss them. Our guide to setting up Sign in with Google covers the client and redirect URIs, and the providers page in the docs lists what each service needs before launch. Shipyard sets up the domain, hosting and other accounts around the app, so the Google console steps above are the part left for you to check by hand.
Sources
- Google for Developers: Using OAuth 2.0 to Access Google APIs (Refresh token expiration)developers.google.com
- Google for Developers: Using OAuth 2.0 for Web Server Applicationsdevelopers.google.com
- Google Cloud Help: Manage App Audiencesupport.google.com
- Auth.js: Google providerauthjs.dev
- Auth.js: Refresh token rotationauthjs.dev
Launch in an hour, not a weekend
Shipyard connects your accounts once, then sets up the domain, hosting, database, email and payments for every new product.