EN
Google OAuth

Common Google OAuth and Gmail API Errors (and How to Fix Each One)

From invalid_grant (Bad Request) to redirect_uri_mismatch, here are 13 Google OAuth errors: the exact message, what causes it, and the fix, in the order you are most likely to meet them.

token-response
POST https://oauth2.googleapis.com/token HTTP/1.1 400 Bad Request { "error": "invalid_grant", "error_description": "Bad Request" }
redirect_uri_mismatchaccess_deniedinvalid_clientinvalid_scope
Short answer

Most Google OAuth errors come from three places: the authorization request, the token endpoint, or your Google Auth Platform settings. The error code tells you which one. invalid_grant (Bad Request) is the most common: Google refused the code or refresh token you sent, and the user has to sign in again.

Quota errors such as 403 userRateLimitExceeded or 429 are covered in our guide to Gmail API limits. For Outlook and IMAP, see the email API guide for developers.

Updated December 2026Checked against Google's OAuth 2.0 documentation

Token endpoint

invalid_grant (Bad Request): causes and fix

invalid_grant means Google refused the grant you sent to the token endpoint. The cause depends on when it happens: when you exchange the code, when you refresh, or with a service account.

The exact error message {"error": "invalid_grant", "error_description": "Bad Request"} {"error": "invalid_grant", "error_description": "Token has been expired or revoked."}
At code exchange
Right after the redirect
CausesThe authorization code was already used (it is single-use) or has expired. The redirect_uri or client ID differs from the authorization request.
FixExchange each code once, quickly, with the same redirect_uri and client. Then restart the flow.
At refresh
Days or months later
CausesApp in Testing (7 days), access revoked, 6 months unused, password changed with Gmail scopes, more than 100 refresh tokens for one account and client, time-limited access ended, admin session control.
FixMark the account as disconnected and ask the user to sign in again.
Service account
Server-to-server JWT
CausesServer clock out of sync or invalid JWT claims.
FixSync the clock with NTP. Details in our service account and domain-wide delegation guide.
reconnect.py
from google_auth_oauthlib.flow import Flow

flow = Flow.from_client_secrets_file('client_secret.json',
    scopes=['https://www.googleapis.com/auth/gmail.send'], redirect_uri=REDIRECT_URI)
# offline = return a refresh token; consent = show the screen again
auth_url, state = flow.authorization_url(access_type='offline', prompt='consent')
# After the redirect: flow.fetch_token(code=code) ONCE, then store
# flow.credentials.refresh_token in place of the old one

Send the user to auth_url from a "Reconnect your Gmail account" button. Why tokens die and how long they live: Google refresh token expiration rules.

Sources: Google's refresh token expiration and RFC 6749, section 5.2, which defines invalid_grant. Last verified: December 4, 2026.

Error 400

Error 400: redirect_uri_mismatch

Google compares the redirect_uri of your request with the Authorized redirect URIs of your OAuth client. One character of difference is enough to block the sign-in.

The exact error message Error 400: redirect_uri_mismatch
Sent in the authorization URLhttp://app.acme.com/oauth/callback/
Registered in Clients > Authorized redirect URIshttps://app.acme.com/oauth/callback
http vs httpstrailing slashalso: port, subdomain, path

Fix it in five steps

  1. Copy the redirect_uri value from the failing request (it is in the URL of the error page).
  2. In Google Cloud console, open Google Auth Platform > Clients and select the client whose ID is in that same request.
  3. Under Authorized redirect URIs, add the value character for character: scheme, host, port, path and trailing slash.
  4. Save. If the error persists right away, retry a few minutes later: new client settings are not always applied instantly.
  5. Send the same redirect_uri to the token endpoint. A different value there returns invalid_grant instead.
On localhost

Register the exact local URI, port included, for example http://localhost:3000/callback. Google accepts http for localhost. A new dev port needs a new entry.

JavaScript origins won't fix it

Authorized JavaScript origins serve browser flows and cause origin_mismatch. This error is fixed only in Authorized redirect URIs.

Error 403

Error 403: access_denied and "Access blocked"

The user never reached a working consent screen, or refused it. The message names your app, and the fix depends on its publishing status and scopes.

The exact error messages Access blocked: [App name] has not completed the Google verification process. Error 403: access_denied error=access_denied (in your redirect URI)
Google hasn't verified this app

The app is requesting access to sensitive info in your Google Account. Until the developer verifies this app with Google, you shouldn't use it.

AdvancedBack to safety
Testing
CauseThe user is not on the test user list.
FixAdd the email under Audience > Test users.
User cap
Cause100 test users, or 100 users of an unverified app over the project's lifetime.
FixSee the 100-user limit.
Unverified scopes
CauseSensitive (gmail.send) or restricted (gmail.readonly, gmail.modify) scopes, app not verified.
FixPublish, then get the app verified.
User choice
CauseThe user clicked Cancel or Back to safety.
FixNothing to repair: explain why you need access and offer to retry.

The "unverified app" screen, the verification steps and the security assessment for restricted scopes are covered in our Google OAuth verification guide. Rules from Google's Manage App Audience. Last verified: December 4, 2026.

Error 400

Error 400: admin_policy_enforced

Not a bug in your code: a Google Workspace administrator blocks your app, or some of its scopes, for that organization. Neither you nor the user can fix it alone.

The exact error message Error 400: admin_policy_enforced
  1. The Workspace admin opens admin.google.com.
  2. Goes to Security > Access and data control > API controls > Manage App Access.
  3. Finds your app by name or client ID and sets it to Trusted for the right organizational unit.
Security>Access and data control>API controls>Manage App Access
Acme CRMOAuth client 1234...apps.googleusercontent.comTrusted
TrustedLimitedSpecific Google dataBlocked

If you build internal tools for your own Workspace, a service account can replace per-user consent: see our Gmail service account and domain-wide delegation guide. Path from Google's control which apps access Google Workspace data. Last verified: December 4, 2026.

Error 400

invalid_scope

Google rejects the whole authorization request before the user sees anything, because one scope in the scope parameter is not valid.

The exact error message Error 400: invalid_scope. Some requested scopes were invalid. {valid=[...], invalid=[...]}
  1. Read the invalid=[...] list: it names the scope Google refused.
  2. Use the full URL, https://www.googleapis.com/auth/gmail.readonly, never the short name gmail.readonly.
  3. Check spelling and spaces between scopes, then that the scope exists for that API.
  4. Declare it in Google Auth Platform > Data Access, then retest the URL.
gmail.labelsNon-sensitiveManage labels only. No verification needed.
gmail.sendSensitiveSend on the user's behalf. App verification required.
gmail.readonly, gmail.modifyRestrictedRead or change mail. Verification plus a security assessment.
https://mail.google.com/RestrictedFull mailbox access, IMAP and SMTP included.

Every Gmail scope and its level: our Gmail API scopes guide, based on Google's Gmail API scopes. Last verified: December 4, 2026.

More errors

8 more Google OAuth errors

Less frequent, quicker to fix. Six come from Google's sign-in and token endpoints, two from the Gmail API call itself.

401invalid_client
MessageError 401: invalid_client
CauseGoogle can't authenticate your OAuth client: wrong client ID or secret, often a secret from another client.
FixCopy both values from the same client in Clients. The console shows only the end of a secret, so create a new one if lost.
401deleted_client
MessageError 401: deleted_client
CauseThe OAuth client was deleted, by hand or automatically after 6 months without token exchanges.
FixRestore it within 30 days from Clients, or create a new client and update your app.
403org_internal
MessageError 403: org_internal
CauseThe app's user type is Internal and the account is outside your Google Cloud Organization.
FixSign in with an organization account, or switch to External: see Internal vs External.
400origin_mismatch
MessageError 400: origin_mismatch
CauseIn a browser flow, the page's scheme, host and port are not an Authorized JavaScript origin.
FixAdd the exact origin, without path, in Clients > Authorized JavaScript origins. Port included.
403disallowed_useragent
MessageError 403: disallowed_useragent
CauseGoogle's sign-in page was opened inside an embedded webview, which Google's policies don't allow.
FixOpen the authorization URL in the system browser, or use a library such as AppAuth on mobile.
400invalid_request
MessageError 400: invalid_request
CauseThe request is malformed: a missing parameter, or an authorization method Google no longer supports.
FixCheck client_id, redirect_uri, response_type and scope, and use the standard web server flow.
403insufficient scopes
MessageRequest had insufficient authentication scopes.
CauseThe Gmail API call needs a scope the access token doesn't carry, for example sending with gmail.readonly only.
FixAdd the scope in Data Access and in your request, then have the user consent again with prompt=consent.
403Gmail API not enabled
MessageGmail API has not been used in project ... before or it is disabled.
CauseOAuth worked, but the Gmail API is off in the Google Cloud project that owns your client.
FixEnable Gmail API in APIs & Services > Library, in that same project, then retry.
Can't find the OAuth consent screen at all?

That is not an error code: the settings moved to Google Auth Platform in Google Cloud console. Select the right project and finish Get started. All six causes are in our guide to the consent screen not showing.

Sources: Google's OAuth 2.0 for web server applications, Gmail API authentication troubleshooting and the Google Auth Platform update of April 28, 2025. Last verified: December 4, 2026.

Build it with Unipile

Use Unipile's verified OAuth app, or bring your own

Connect your users' Gmail and Google Calendar accounts through hosted authentication, on Unipile's CASA Tier 2 certified Google OAuth app or on your own credentials. See the Email API for Gmail, Outlook and IMAP, used by 6,000+ companies, and start with a 7-day trial.

With Unipile

Which errors go away with a verified OAuth app?

With Unipile's Google OAuth app, the client, redirect URIs, scopes and verification are Unipile's. Some errors stay possible, because they depend on the user or their administrator.

Handled by Unipile's OAuth appDefault
No client of yours to misconfigure: no redirect_uri_mismatch, origin_mismatch, invalid_client or deleted_client on your side Verified app, CASA Tier 2 certified: no "unverified app" screen and no 100-user cap on Unipile's verified OAuth app Scopes set by Unipile: gmail.labels, gmail.send, gmail.modify, gmail.readonly, calendar, calendar.events Tokens stored encrypted, in transit and at rest
Still possible, whatever the appUser side
admin_policy_enforced: the Workspace admin must trust the app Revoked access: the account turns disconnected and a webhook fires Gmail quotas still apply: see Gmail API limits Your own credentials: the client errors above are yours again
Reconnect a disconnected account

Create a Hosted Auth link with POST /v2/auth/link and pass the existing account_id instead of providers. See Hosted Auth and the account status lifecycle.

Unipile is an independent technical intermediary that calls Google APIs on behalf of each authenticated user. It is not affiliated with, endorsed by, or sponsored by Google. This is not a workaround for Google's security review: Unipile's app went through it. Bring your own app at any time with the redirect URI https://api.unipile.com/v2/auth/oauth/callback, as described in the Google OAuth documentation. Product page: Gmail API integration. See also security and compliance (SOC 2 Type II).

Google OAuth Errors FAQ

Quick answers on invalid_grant, redirect_uri_mismatch, invalid_client and the other Google OAuth errors.

Google refused the authorization code or refresh token you sent to the token endpoint. At code exchange, the code was reused, expired or sent with a different redirect URI. At refresh, the token expired or was revoked. The user must sign in again.

The redirect_uri in your request does not exactly match one of the Authorized redirect URIs of your OAuth client. Scheme, host, port, path and trailing slash must all be identical. Fix it in Google Auth Platform > Clients.

Because the registered URI and the one your dev server uses differ, often by the port (3000 vs 3001) or a trailing slash. Register the exact local URI, for example http://localhost:3000/callback. Google accepts http for localhost.

No. JavaScript origins are checked for browser-based flows and cause origin_mismatch when wrong. A redirect_uri_mismatch is fixed only in the Authorized redirect URIs field of the same client.

Google could not authenticate your OAuth client: the client ID or client secret is wrong, often a secret copied from another client or rotated. Since 2025 the console shows only the last characters of a secret, so create a new one if you lost it.

Google blocked the request before the consent screen. Usual causes: the user is not a test user of an app in Testing, the app requests sensitive or restricted scopes without verification, or the user clicked Cancel, which returns access_denied.

A Google Workspace administrator blocks your app or some of its scopes for that organization. The user cannot fix it. A Workspace admin must mark the app as Trusted in the Admin console, under Security > Access and data control > API controls.

Google's sign-in page was opened inside an embedded webview, which Google's OAuth policies do not allow. Open the authorization URL in the system browser instead, or use a library such as AppAuth on mobile.

Still have questions? Our team is here to help.

Talk to an expert