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:
- 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!
- 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.
- 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.
- Restart n8n After Making Changes
If you updated environment variables or config (like base URL), restart the Docker container:
docker restart n8n
- 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.