OAuth Redirect URL stuck with `localhost` and consent windows complains on Error 400: redirect_uri_mismatch

Disclaimer: I’ve seen several issues on this problem, but none resolved my problem.

When creating new Gmail OAuth credentials, the redirect URL is stuck on localhost. I can’t figure out why and where is this coming from. :point_down:

Then on the consent window I am receiving this error Error 400: redirect_uri_mismatch : :point_down:

I’m not sure the two are related, I only suspect they do.

FWIW, I used the external URL in Google:

I’m not so sure as to how to debug this issue.

My configuration:

  • Running self-hosted in a Docker
  • My .env:
N8N_RUNNERS_ENABLED=true
VUE_APP_URL_BASE_API=https://n8n.example.com/
# N8N_HOST=localhost
N8N_HOST=n8n.example.com
N8N_PORT=5678
N8N_PROTOCOL=https
N8N_EDITOR_BASE_URL=https://n8n.example.com/
N8N_DIAGNOSTICS_ENABLED=false

WEBHOOK_URL=https://n8n.example.com/
WEBHOOK_TUNNEL_URL=https://n8n.example.com/

Information on your n8n setup

  • n8n version: 1.83.2
  • Database (default: SQLite): Postgresql
  • n8n EXECUTIONS_PROCESS setting (default: own, main): ??
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Raspberri Pi OS

OK - Very strange. After reading this post I went back to Google API config and added the localhost redirection URL.

The immediate result was that the OAuth2 dialogue presented me with my Google accounts (!!!). However once I approved the permissions the process breaks because the browser is then trying to redirect to localhost and this obviously doesn’t work.

So I’m one step forward, but still no solution.

With the variables you’ve setup, the redirect URI in n8n editor should match the domain you’ve setup. Are you sure the env vars are being read/applied?

@hrishikesh I’m sure but then I may be wrong. How should I go on verify this?

If I could use one of the nodes in order to run something like echo $ENV['N8N_HOST] or echo $N8N_HOST then I guess that would be decisive.
Can I ?

That should be possible using the code node: process.env.N8N_HOST

Thanks @hrishikesh. When using process I’m getting an error Cannot find name 'process'. Do you need to install type definitions for node? Try npm i --save-dev @types/node.

Same goes for using $env:man_shrugging:

Problem solved! I’m using n8n’s self hosted starter kit which uses docker-compose.
The variables I have in .env are not picked up by docker unless explicitly adding an -env_file directive to docker-compose.yml

I opened a PR just in case: Include .env in docker-compose.yml by zohar · Pull Request #43 · n8n-io/self-hosted-ai-starter-kit · GitHub

1 Like

Now it happens in form node… :man_facepalming: :man_facepalming: :man_facepalming: :man_facepalming:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.