Error 400: redirect_uri_mismatch - Setting up Gmail credentials

Describe the problem/error/question:

I am trying to connect my Gmail account to n8n using the Gmail node, but I’m getting a “Error 400: redirect_uri_mismatch” error during the OAuth flow. I’ve already checked that the redirect URIs in Google Cloud Console and the n8n Gmail node match exactly, but the error persists.

What is the error message (if any)?:

Error 400: redirect_uri_mismatch

Please share your workflow:

(I haven’t been able to successfully connect to Gmail yet, so I don’t have a working workflow to share. I’m stuck at the OAuth stage.):
N/A

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 1.77.3 (Based on the output when you started your Docker container)
  • Database (default: SQLite): PostgreSQL (You have a n8n_postgres container running)
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • **Running n8n via (Docker, npm, n8n cloud, desktop app):**Docker
  • **Operating system:**Windows

Hmm… let’s try a few things:

  1. Run the consent screen process again
  2. Publish the app (sometimes a test app is not enough)
  3. Restart your n8n instance

Let me me know if any of those work.

Also, it may seem obvious, but check if you are getting the credentials from the same account you are trying to connect in n8n.

i try to deploy n8n on my vps, and set
environment:
- NODE_ENV=production
- N8N_HOST=n8n.my.domain
- WEBHOOK_URL=https://n8n.my.domain
but still have this error

OK, i waited for about 30 min and it worked now. it’s google console delay i thought.

Hi @Leam_Hamilton

The “Error 400: redirect_uri_mismatch” during Gmail OAuth setup in n8n is almost always due to Google not recognizing the redirect URI used during authentication, even if it looks correct.

Let’s walk through how to fix it step by step:


  1. Confirm the Correct Redirect URI

In your Google Cloud Console, make sure this exact redirect URI is listed under: OAuth 2.0 Client IDs → Authorized redirect URIs

If you’re using Docker with a domain like https://n8n.example.com, then your redirect URI should be:

https://n8n.example.com/rest/oauth2-credential/callback

If you’re using localhost for development:

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

Make sure there’s no trailing slash!


  1. Where to Find the Correct Redirect URI in n8n

You can get the exact URI from n8n by:

Going to Credentials in n8n

Choosing Gmail OAuth2

Click Edit, and under the credential config, n8n shows you:

“You need to register the following URL as authorized redirect URI…”

Copy that URI and paste it exactly into your Google Cloud OAuth settings.


  1. Common Gotchas

Make sure you’re editing the correct client in Google Cloud (some folks have several and mix them up).

Ensure the domain used in the redirect URI has a valid HTTPS certificate.

If you’re using a reverse proxy (e.g., NGINX), check that it forwards everything to /rest/oauth2-credential/callback.


  1. Restart n8n After Making Changes

If you updated environment variables or config (like base URL), restart the Docker container:

docker restart n8n


  1. Optional: Add Environment Variables

In your Docker .env file (or as container env vars), you can set:

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

This helps n8n build the correct redirect URI during OAuth flows.


I hope this helps.

2 Likes

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