A8gent
All articles

Technical

Error 400: redirect_uri_mismatch in n8n: 6 Causes and the Fix for Each

Google refuses the sign-in because the callback URL n8n sends is not one registered on your OAuth client. On self-hosted n8n that URL is usually http://localhost:5678, because n8n was never told its public address. Here is how n8n builds the URL, and the fix for each way it goes wrong.

A8gentAutomation practiceNovember 17, 202610 min read

Short answer: Google shows Error 400: redirect_uri_mismatch when the OAuth Redirect URL n8n sends is not listed on your Google OAuth client. On self-hosted n8n it is usually http://localhost:5678/rest/oauth2-credential/callback because n8n was never told its public URL. Set N8N_EDITOR_BASE_URL (and WEBHOOK_URL) to your https domain, restart n8n, then paste the new OAuth Redirect URL into Authorized redirect URIs in Google Cloud exactly.

Contents
  1. The Short Answer
  2. How n8n Builds the OAuth Redirect URL
  3. Cause 1: n8n Has No Public URL Configured
  4. Cause 2: N8N_EDITOR_BASE_URL Points Somewhere Else
  5. Cause 3: The Variables Never Reached n8n
  6. Cause 4: Google's List Does Not Match Exactly
  7. Cause 5: Google Will Not Accept the URI You Need
  8. Cause 6: Google Has Not Applied the Change Yet
  9. Still Broken? Check These in Order
  10. How to Stop It Coming Back
  11. Sources
  12. FAQ

The Short Answer

Error 400: redirect_uri_mismatch is Google telling you that the redirect_uri in the sign-in request does not match an authorized redirect URI for the OAuth client ID. n8n sends the value shown in the OAuth Redirect URL field of your credential. Google compares it, character for character, with the Authorized redirect URIs on the client in Google Cloud.

The n8n Google OAuth2 documentation gives the basic fix: copy the OAuth Redirect URL from the n8n credential and paste it exactly, including the protocol and port, into Authorized redirect URIs.

That fix assumes the URL n8n shows is the right one. On a self-hosted server it often is not. It shows:

http://localhost:5678/rest/oauth2-credential/callback

That is n8n's default, built from N8N_PROTOCOL=http, N8N_HOST=localhost and N8N_PORT=5678. Unless n8n runs on the machine you browse from, Google cannot send you back there. So: tell n8n its public URL, then register that URL with Google.

How n8n Builds the OAuth Redirect URL

The documentation does not spell out the order, so we read it from the source. In url.service.ts, n8n works out an instance base URL, and frontend.service.ts appends /rest/oauth2-credential/callback to it. The base URL is the first of these that is set:

  1. N8N_EDITOR_BASE_URL
  2. N8N_WEBHOOK_URL (from n8n 2.30.0), then the older WEBHOOK_URL
  3. N8N_PROTOCOL://N8N_HOST:N8N_PORT plus N8N_PATH, with the port left out for http on 80 and https on 443

The same order applies in n8n 1.x, minus N8N_WEBHOOK_URL, which did not exist yet. The endpoints reference says WEBHOOK_URL is deprecated from 2.35.0 but still works as an alias, with a warning in the log.

Two old answers are still copied around and no longer apply. The 2020 forum reply recommending WEBHOOK_TUNNEL_URL predates the current variables. And names like N8N_EXTERNAL_HOSTNAME or N8N_PORT_EXTERNAL, which turn up in later threads, are not n8n settings at all. Setting them does nothing.

SymptomCauseFixHow to confirm
Redirect URL shows http://localhost:5678/...No public URL configuredSet N8N_EDITOR_BASE_URL and the webhook URLThe credential field still says localhost after a restart
Redirect URL shows a wrong domain or httpN8N_EDITOR_BASE_URL set to the wrong valueCorrect or remove itIts value matches what the field shows
You set the variables and nothing changedThe variables never reached n8nPass them in the way your install method reads themPrint the process environment
Field shows the right URL, Google still says mismatchGoogle's list differs, or a different clientPaste the exact URL into the right clientCompare redirect_uri in Google's error details
Google will not save the URIhttp or a raw IP on a public hostUse a domain with HTTPSGoogle shows a validation message on save
Everything matches, still failingGoogle has not applied the changeWait and retryThe client was edited minutes ago

Cause 1: n8n Has No Public URL Configured

The most viewed thread on this, OAuth Callback URL is localhost:5678, is this case: the instance is reachable at a real domain, and n8n still believes it is localhost:5678.

How to confirm it: open the credential in n8n and read the OAuth Redirect URL field. It is generated by the server from the settings above, so it shows exactly what n8n will send to Google.

The fix: set the editor URL and the webhook URL to your public HTTPS address. With Docker Compose:

services:
  n8n:
    environment:
      - N8N_HOST=n8n.example.com
      - N8N_PROTOCOL=https
      - N8N_EDITOR_BASE_URL=https://n8n.example.com/
      - WEBHOOK_URL=https://n8n.example.com/
      - N8N_PROXY_HOPS=1

On n8n 2.30.0 or later, use N8N_WEBHOOK_URL in place of WEBHOOK_URL. N8N_PROXY_HOPS=1 is what the reverse proxy documentation asks for when n8n sits behind one proxy. It does not change the redirect URL, but you need it in the same setup.

Recreate the container so it picks up the change, then reopen the credential:

docker compose up -d --force-recreate n8n

The same variables set the webhook URLs n8n gives to other services.

Cause 2: N8N_EDITOR_BASE_URL Points Somewhere Else

Because N8N_EDITOR_BASE_URL is checked first, a stale value wins over a correct WEBHOOK_URL. Typical leftovers are http://localhost:5678/ from a local test, the old domain after a move, or http where the site now runs on https.

How to confirm it: the OAuth Redirect URL matches your N8N_EDITOR_BASE_URL value and not your webhook URL.

The fix: set it to the address people type to open the editor, with https and without a port if the proxy serves it on 443:

N8N_EDITOR_BASE_URL=https://n8n.example.com/

If n8n is served under a sub-path, the redirect URL includes it, for example https://example.com/n8n/rest/oauth2-credential/callback. Whatever the field shows after the restart is what Google must have.

Cause 3: The Variables Never Reached n8n

This is behind most "I set WEBHOOK_URL and it still says localhost" replies. In one solved thread, every variable was correct in a .env file, but the docker-compose.yml did not load that file into the container. In the original thread, export WEBHOOK_URL=... followed by sudo n8n start failed because sudo does not pass your shell's variables on, and plain n8n start worked.

How to confirm it: print the environment n8n actually runs with. For Docker, replace n8n with your service name:

docker compose exec n8n env | grep -E 'N8N_|WEBHOOK_URL'

The fix, by install method:

# Docker Compose: load the .env file into the container
services:
  n8n:
    env_file:
      - .env

# npm, same shell
export N8N_EDITOR_BASE_URL=https://n8n.example.com/
n8n start

# npm with sudo: put the variable on the command line
sudo N8N_EDITOR_BASE_URL=https://n8n.example.com/ n8n start

# systemd unit, then daemon-reload and restart
Environment="N8N_EDITOR_BASE_URL=https://n8n.example.com/"

A .env file next to docker-compose.yml is only used to fill ${VARIABLES} written in the compose file. It is not passed into the container unless you list the variables under environment or add env_file.

Cause 4: Google's List Does Not Match Exactly

n8n now shows the right URL and Google still refuses. Then the difference is on the Google side. Google matches the whole string, so each of these is a mismatch:

  • http registered, https sent, or the reverse.
  • :5678 in one and not the other.
  • A trailing slash after callback.
  • The URI added to a different OAuth client from the one whose Client ID is in n8n. A project often holds several clients.

How to confirm it: on Google's error page, open the error or request details where offered, and read the redirect_uri that was sent. Then open the client in Google Cloud under APIs & Services > Credentials and check its Client ID against the one in n8n.

The fix: click the copy button on the n8n field, paste it into Authorized redirect URIs on the matching client, and save.

Cause 5: Google Will Not Accept the URI You Need

Google's redirect URI validation rules say redirect URIs must use HTTPS and hosts cannot be raw IP addresses. Localhost is exempt from both. So http://localhost:5678/... is accepted, and http://203.0.113.10:5678/... is not. One user in the access token thread running n8n on a NAS by IP got "Invalid redirect: Must end with a public top-level domain (such as .com or .org)."

The fix: give the instance a domain name and HTTPS, usually with a reverse proxy in front. Then use Cause 1. If n8n really is only on your own machine, the n8n docs confirm you need no public domain: register the localhost URL and open n8n at http://localhost:5678, not by IP, when you connect.

Our guide to the true cost of self-hosting n8n and the glossary entry on self-hosting cover what running your own server involves.

Cause 6: Google Has Not Applied the Change Yet

Google's OAuth client help page warns that it may take 5 minutes to a few hours for changes to these settings to take effect. If you added the URI a minute ago and everything now matches, wait, then select Sign in with Google in the credential again.

Still Broken? Check These in Order

  1. The OAuth Redirect URL in n8n shows your public https address, not localhost.
  2. env inside the running container or process lists N8N_EDITOR_BASE_URL with that same address.
  3. The redirect_uri in Google's error details equals the n8n field exactly.
  4. The Client ID in n8n belongs to the OAuth client you edited, of type Web application.
  5. The domain is listed under Branding > Authorized domains, as the n8n setup guide asks.
  6. You waited at least a few minutes after the last edit in Google Cloud.

Failing on a different screen now? "Access blocked" is covered in Access blocked: has not completed the Google verification process. A credential that connects but fails when a node runs: Unable to sign without access token.

How to Stop It Coming Back

Set the public URL on day one. Put N8N_EDITOR_BASE_URL and the webhook URL in your deployment file before you create any credential. They decide every OAuth callback and every webhook address n8n hands out.

Keep the domain stable. Moving n8n to a new domain changes every redirect URI. Register the new one in each OAuth client before you switch over, then reconnect each OAuth credential.

Check the field after every redeploy. A rebuilt container that lost its environment shows localhost again.

The n8n AI Agents course covers building agents with tools and memory, wiring webhooks and triggers, handling errors, and deploying self-hosted or on n8n Cloud. For Google Sheets as an agent tool, see our n8n AI agent with Google Sheets walkthrough, and for the platform overall, our n8n review.

Sources

Checked against n8n's documentation and source, Google's documentation and the n8n community forum on 17 November 2026.

FAQ

What does Error 400: redirect_uri_mismatch mean in n8n?
Google received a sign-in request whose redirect URI is not in the Authorized redirect URIs of the OAuth client you are using. n8n sends the URL shown in the OAuth Redirect URL field of the credential, so either that URL is wrong, usually localhost on a server, or Google's list does not contain it exactly.
Why does the n8n OAuth Redirect URL show localhost:5678?
n8n builds it from N8N_EDITOR_BASE_URL, then the webhook URL, then N8N_PROTOCOL, N8N_HOST and N8N_PORT, whose defaults are http, localhost and 5678. If none of the first two are set and the host is left at its default, you get http://localhost:5678/rest/oauth2-credential/callback.
Which environment variable changes the OAuth callback URL in n8n?
N8N_EDITOR_BASE_URL takes priority. If it is not set, n8n uses N8N_WEBHOOK_URL (from 2.30.0) or WEBHOOK_URL. Set the editor URL to your public https address and restart n8n so the process reads it.
I set WEBHOOK_URL and the callback still shows localhost. Why?
Either the variable did not reach the n8n process, for example a .env file Docker Compose does not load or sudo dropping it, or N8N_EDITOR_BASE_URL is set to localhost and overrides it. Print the environment inside the container to see which.
Can I use an IP address as the Google redirect URI?
Not for a public server. Google's rules say redirect URIs must use HTTPS and hosts cannot be raw IP addresses, with an exemption for localhost. Use a domain name with HTTPS, or connect from the same machine through http://localhost:5678.
Do I need a domain to use Google OAuth with n8n on my own computer?
No. The n8n docs say Google accepts localhost as a redirect URI for local instances, so you need no public domain, SSL certificate or port forwarding. Register http://localhost:5678/rest/oauth2-credential/callback and open n8n at that address when you connect.

If this resonated

Module 02 is the long version of this post.

Eval set, refusal pattern, kill switch. Build it in a weekend.

All postsLast verified 2026-11-17

Done for you

Want this built for your business?

Tell us the workflow. We scope, build, and ship the agent with guardrails and the numbers to prove it worked. The scoping call is free.

Free scoping call. You own the code.

Request a scoping call