When Cloud & Workspace displays Error: redirect_uri_mismatch, Google Identity OAuth 2.0 servers strictly compare the redirect_uri parameter sent in the authorization URL against the whitelist registered under your OAuth 2.0 Client ID in Google Cloud Console. Any mismatch in protocol (http vs https), trailing slash (/), port, subdomain, or script ID immediately blocks login with Error 400.
Step-by-Step Resolution
- Click "error details" or inspect the browser address bar to read the exact redirect_uri your application transmitted during the OAuth request.
- Open Google Cloud Console > APIs & Services > Credentials, and open your Web Application OAuth 2.0 Client ID.
- Under "Authorized redirect URIs", paste the exact character-for-character redirect URI (for Apps Script apps-script-oauth2, verify https://script.google.com/macros/d/{SCRIPT_ID}/usercallback).
- Click Save and wait 5 minutes for Cloud configuration propagation before retrying login.
Common Edge Cases
Local development on http://localhost:3000 vs http://127.0.0.1:3000 or reverse proxies terminating HTTPS behind nginx/Cloudflare (where the app generates http:// internally instead of https://) commonly causes subtle URI mismatches.
When This Doesn't Work
If running behind a reverse proxy or Next.js frontend, confirm NEXTAUTH_URL or trustProxy headers match the public HTTPS origin so the callback URI is not rewritten to localhost or HTTP.
Prevention Tips
Maintain separate OAuth Client IDs for local development (http://localhost:...) and production HTTPS domains cleanly in environment configs.
Relevant Tools & Guides
- URL Encoder / Decoder — Encode special characters into URL-safe UTF-8 percent-encoding and decode back.
- JSON Formatter & Validator — Format, beautify, inspect syntax errors, and minify JSON payloads.
- Read Google Cloud IAM Best Practices: Enforcing Least Privilege, Custom Roles & Service Accounts →
- Read Google Apps Script Automation Guide: Connect Workspace Services with Code →
Related Errors
Frequently Asked Questions
Do trailing slashes matter in Google Authorized Redirect URIs?
Yes. https://example.com/callback and https://example.com/callback/ are treated as completely different URIs by Google OAuth.
How long do Cloud Console OAuth changes take to apply?
Usually seconds to 5 minutes, though Google advises allowing a short propagation window after saving.
Are wildcard domains supported in Authorized redirect URIs?
No. Google Cloud prohibits wildcards like *.example.com in redirect URIs for security reasons; every exact callback URL must be listed.
What is the callback URL format for Apps Script OAuth2 library?
It uses https://script.google.com/macros/d/{YOUR_SCRIPT_ID}/usercallback using your Project Script ID.