Google sign-in stops with Error 400: redirect_uri_mismatch
Error 400: redirect_uri_mismatchShort answer
Google compares the redirect_uri in your request with the authorized redirect URIs of that OAuth client, character by character. Copy the redirect_uri from the error page or the request URL, then register that exact value on the same client ID. Scheme, case and trailing slash all count, and wildcards or raw IP addresses are not allowed.
Fix it fast
1Find out which cause you have
Open the failing sign-in URL and read the redirect_uri query parameter exactly as your app sent it. That string is what must be registered.
# In the browser address bar of the Google error page, or from your app's log: # https://accounts.google.com/o/oauth2/v2/auth?client_id=...&redirect_uri=https%3A%2F%2Fapp.example.com%2Fauth%2Fcallback&... python3 -c "import urllib.parse as u,sys; print(u.unquote(sys.argv[1]))" "https%3A%2F%2Fapp.example.com%2Fauth%2Fcallback"2Match what you see, then jump to its fix
- 1
The redirect_uri in the request differs by scheme, case, trailing slash, port or path from every authorized URIThe value registered on the client is not exactly the value your app sendsFix - 2
The URI is registered, but in a different client from the one named by client_id in the requestThe request uses a client ID from another project or clientFix - 3
The console rejects the entry, or your app is generating http:// on a public host, a raw IP, a wildcard or a #fragmentThe URI breaks Google's rules, so it cannot be registered as writtenFix
- 1
What does the error look like?
Error 400: redirect_uri_mismatchredirect_uri_mismatch
Cause 1 of 3
The value registered on the client is not exactly the value your app sends
1Check
Google says the scheme, case and trailing slash must all match. Compare the decoded redirect_uri from the first step with the list on the client in the Google Cloud Console.
# Console > the project > Clients > your Web application client > Authorized redirect URIs2Fix
Add the exact value from the request to Authorized redirect URIs, or change the app's setting so it sends a value that is already registered. Do not register a pattern.
# Register this exact string (example):
https://app.example.com/auth/callback3Verify
Start the sign-in again. Google shows the account chooser instead of the 400 page.
# Retry sign-in in a fresh browser tabConfirmed by developers.google.com
Cause 2 of 3
The request uses a client ID from another project or client
1Check
Redirect URIs belong to one OAuth client. Staging and production often use different client IDs, and an environment variable can point the app at the wrong one.
# compare the client_id in the failing request with the client you edited
env | grep -i google_client_id2Fix
Register the URI on the client whose client_id is in the request, or set the correct client ID and secret for that environment.
# Set GOOGLE_CLIENT_ID to the client that lists the redirect URI, then restart the app3Verify
The authorization request now carries the client ID you edited, and sign-in succeeds.
# Check the client_id parameter of the new sign-in URLConfirmed by developers.google.com
Cause 3 of 3
The URI breaks Google's rules, so it cannot be registered as written
1Check
Google requires https for redirect URIs, except localhost and loopback addresses. It does not allow raw IP addresses (other than localhost), wildcards, a fragment, userinfo, or path traversal. Behind a proxy, many frameworks build the redirect URI as http:// because they do not see the original scheme.
# Print the redirect URI your framework generates and look at its scheme and host2Fix
Use a hostname with https for public sites, and for local development use http://localhost:<port>. Make the app build its URI from your public https address (trust the proxy's forwarded scheme or set an explicit base URL).
# good
https://app.example.com/auth/callback
http://localhost:8080/auth/callback
# not accepted
http://203.0.113.10/auth/callback
https://*.example.com/auth/callback3Verify
Register the corrected value and repeat sign-in; the request's redirect_uri now equals a registered entry.
# Compare the new redirect_uri with the console listConfirmed by developers.google.com
How do I stop it coming back?
- Keep one OAuth client per environment and write down the redirect URI of each in the repository's README.
- Set the redirect URI from one configuration value, not from the incoming request host.
- Register the local development URI separately and never add wildcard-like patterns.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Related fixes
Security
Entra ID token request fails: the request body must contain the parameter 'grant_type'
AADSTS900144: The request body must contain the following parameter: 'grant_type'.
The token endpoint did not find grant_type in the form body of your POST.
3 causes, each with a fixSecurity
Angular HttpClient does not add the X-XSRF-TOKEN header to a request
403 Forbidden on POST, PUT or DELETE while GET works
Angular copies the XSRF-TOKEN cookie into an X-XSRF-TOKEN header only for mutating requests to the same origin, and only when the cookie is readable by script.
5 causes, each with a fixSecurity
An [Authorize] endpoint rejects a request with a bearer token
Authorization Header sent: no Bearer token sent.
An [Authorize] endpoint without a policy name requires an authenticated user.
4 causes, each with a fixSecurity
ASP.NET Core API rejects an Angular user's token: the signature key was not found
401 Unauthorized
The API looked for the key named by the token's kid in the key set it downloaded from your Authority, and the key was not there.
4 causes, each with a fixSecurity
ASP.NET Core rejects the token before checking it: IDX12741, three segments expected
401 Unauthorized
IDX12741 means the string the API pulled out of the Authorization header is not shaped like a JWT: a signed token has three dot-separated parts and an encrypted one has five.
3 causes, each with a fixSecurity
A Microsoft Entra access token shows Invalid Signature when you check it yourself
Tokens that a Microsoft API receives might not always be a JWT that can be decoded
A token issued for Microsoft Graph is not meant for you to validate, so a failed signature check is expected.
2 causes, each with a fix