Steps
Copy the redirect URL from n8n
Open the credential (for example Google OAuth2 API or Gmail OAuth2 API). n8n shows an OAuth Redirect URL such as
https://n8n.example.com/rest/oauth2-credential/callback. This is the exact URL n8n sends to the provider. If it showslocalhostor a port like:5678on a server, fix n8n's settings first (step 2).Make n8n use your public address
Set
WEBHOOK_URL=https://your-domain/(and, to be explicit,N8N_EDITOR_BASE_URL=https://your-domain/) and restart n8n. In our test,N8N_HOSTplusN8N_PROTOCOLalone producedhttps://n8n.example.com:5812/..., with the internal port, which Google then rejects.Paste the exact URL into the provider
In Google Cloud Console go to APIs & Services → Credentials, open the OAuth client (type Web application) and add the URL under Authorized redirect URIs. Same scheme, host, port and path, character for character. Save; Google says changes can take a few minutes to apply.
Check Client ID and Secret
A wrong Client ID stops at Google: “The OAuth client was not found.
Error 401: invalid_client”. A wrong secret gets past Google and fails back in n8n with “Client authentication failed”. Copy both again from the same OAuth client.Connect from the right browser
Click Connect my account (or Sign in with Google) while logged in to n8n at the public address, and allow the pop-up. A callback that lands in a browser not logged in to n8n gives
Unauthorized, and reusing an old callback link givesThe OAuth callback state is invalid!.
Where n8n gets the redirect URL
n8n builds the URL from its own settings, not from the address in your browser. On n8n 2.43.7 we started n8n with different settings and read the OAuth Redirect URL it showed, then created a Google credential and looked at the redirect_uri it actually sent to Google. The two always matched.
| n8n settings | Redirect URL n8n uses | What it means |
|---|---|---|
No URL settings (plain n8n start on port 5811) | http://localhost:5811/rest/oauth2-credential/callback | Fine for local testing only: the callback only works in a browser on the machine n8n runs on. |
N8N_HOST=n8n.example.com + N8N_PROTOCOL=https, n8n on port 5812 behind a proxy | https://n8n.example.com:5812/rest/oauth2-credential/callback | The internal port is added to the public URL. If you registered the URL without :5812, Google says redirect_uri_mismatch. |
WEBHOOK_URL=https://n8n.example.com/ only | https://n8n.example.com/rest/oauth2-credential/callback | Correct. With no editor URL set, n8n uses the webhook URL for the editor and OAuth too. |
N8N_EDITOR_BASE_URL=https://n8n.example.com only | https://n8n.example.com/rest/oauth2-credential/callback | Correct for OAuth, but webhook URLs still showed http://localhost:5814/. Set both. |
N8N_EDITOR_BASE_URL with a trailing slash | https://n8n.example.com/rest/oauth2-credential/callback | Same URL, no double slash. The trailing slash doesn't matter. |
WEBHOOK_URL=https://n8n.example.com/ and N8N_EDITOR_BASE_URL=https://editor.example.com/ both set (Docker, n8n 2.43.7, 30 Oct) | https://editor.example.com/rest/oauth2-credential/callback | N8N_EDITOR_BASE_URL wins. If the two differ, register the editor address in the provider, or make them the same. |
WEBHOOK_URL=https://n8n.example.com/ + N8N_PATH=/n8n/ (Docker, 30 Oct) | https://n8n.example.com/rest/oauth2-credential/callback | N8N_PATH was not added to the redirect URL. If your proxy serves n8n under a subpath, compare this URL with your real public path before pasting it into the provider. |
N8N_PORT=443 to hide the port | n8n refused to start: n8n does not have permission to use port 443. Please run n8n with a different port. | Keep n8n on 5678 and set WEBHOOK_URL or N8N_EDITOR_BASE_URL instead. |
For a server behind a reverse proxy on a normal HTTPS address, this is enough:
# docker-compose.yml (service n8n, environment)
- N8N_HOST=n8n.example.com
- N8N_PROTOCOL=https
- WEBHOOK_URL=https://n8n.example.com/
- N8N_EDITOR_BASE_URL=https://n8n.example.com/Restart n8n, open the credential again, copy the new OAuth Redirect URL and paste it into the provider (for Google: Google Cloud Console → APIs & Services → Credentials → your OAuth client → Authorized redirect URIs). The proxy itself must also pass the right host, see n8n “Connection lost” behind a reverse proxy.
Every callback error we triggered
Then we ran the sign-in itself: once against Google with a test client, and against a small local OAuth server that let us choose the answer. Each row is one run.
| What happened | What n8n or Google showed | Fix |
|---|---|---|
| Google, with a client ID Google doesn't know | Google page “Access blocked: Authorization Error. The OAuth client was not found. Error 401: invalid_client” | Copy the Client ID again from Google Cloud Console, with no spaces, and check it belongs to the project you think. |
| Callback opened with no parameters | Insufficient parameters for OAuth2 callback. Received following query parameters: {} | The provider didn't send a code back. Start again from Connect my account. |
User clicks Cancel or Deny on the consent screen (error=access_denied) | Same Insufficient parameters message, with "error":"access_denied" in the details | Not a bug: accept the consent screen. On Google, an app in Testing only lets in the test users you added. |
Callback with a broken state | Invalid state format | The URL was cut or edited. Don't copy callback links by hand. |
| Valid callback opened in a browser that isn't logged in to n8n | Unauthorized | Open n8n and click Connect my account in the same browser, on the same address (not localhost in one tab and your domain in another). |
| The same callback opened a second time | The OAuth callback state is invalid! | Each sign-in link works once. Click Connect my account again. |
| Token exchange with a client Google doesn't know (real Google token endpoint), or a rejected secret (mock server) | Client authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method). Details: invalid_client | Paste the Client Secret again. If you reset it in the provider, update n8n too. |
Token endpoint answers invalid_grant | The provided authorization grant ... is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client. | The code expired or was already used, or the redirect URL changed between the two steps. Reconnect once, quickly. |
Token endpoint answers redirect_uri_mismatch | Bad Request, details redirect_uri_mismatch | n8n sends the same redirect URL again when it swaps the code for a token, so a wrong URL fails here too. |
| Token endpoint answers correctly | “Connection successful. This window will close automatically in 5 seconds.” | Done. The credential now holds an access token. |
Token endpoint answers with no refresh_token | Also “Connection successful” | n8n doesn't warn you. Without a refresh token it can't renew access when the token expires (we didn't wait for expiry). |
Why it says redirect_uri_mismatch when the URL looks right
Google compares the URL character by character. In our runs the usual differences were a port (:5812) added by N8N_HOST, http instead of https, and localhost because no public URL was set. The sign-in pop-up's address contains the redirect_uri n8n sent, so you can compare it with the list in Google Cloud Console. Whatever n8n shows as OAuth Redirect URL is exactly what it sends: change n8n's settings, or add that exact URL to the provider, but make them identical.
Quick checklist
- The OAuth Redirect URL in the n8n credential is your public HTTPS address, with no internal port and no
localhost. - That exact URL is in the provider's allowed redirect URLs (Google: Authorized redirect URIs, not JavaScript origins).
- Client ID and Client Secret come from the same OAuth client, pasted without spaces.
- You click Connect my account in a browser that is logged in to n8n, at the public address, and allow the sign-in pop-up (n8n says “Sign-in window was blocked” otherwise).
- Google app in Testing: your Google account is in the test users list.
- Reconnect after changing any of these. Each sign-in link works only once, and n8n's source keeps the sign-in state for 5 minutes.
Good to know
- Gmail node failing with
Client authentication failed,invalid_grantorInvalid email address: n8n Gmail node not working. - Google Sheets node failing with
Bad request,invalid_grantor a private key error: n8n Google Sheets node not working. - Slack node failing with
invalid_authornot_authed: n8n Slack node not working. - Webhook URLs still show
localhost? That'sWEBHOOK_URL, covered in n8n self-hosting errors. - A credential that connected but fails later with 401 or 403: see n8n credential errors and HTTP Request node errors.
What we didn't test
- A real Google OAuth client, so we couldn't show Google's own
Error 400: redirect_uri_mismatchpage; the URL comparison above is what triggers it. - Microsoft, Slack, HubSpot and other providers, n8n Cloud, and token expiry and refresh.
Start from a working agent
FAQ
How do I fix redirect_uri_mismatch in n8n?
Copy the OAuth Redirect URL shown in the n8n credential and add exactly that URL to the provider's allowed redirect URIs (Google Cloud Console, Credentials, your OAuth client). If n8n shows localhost or an internal port, set WEBHOOK_URL (or N8N_EDITOR_BASE_URL) to your public HTTPS address, restart n8n and copy the new URL.
Why does the n8n OAuth redirect URL show localhost?
n8n builds the redirect URL from its own settings, not from your browser. With no WEBHOOK_URL or N8N_EDITOR_BASE_URL set, it uses http://localhost:5678. Set one of them to your public address and restart.
Why does my n8n redirect URL contain :5678?
Setting N8N_HOST and N8N_PROTOCOL without a public URL keeps n8n's internal port in the address. In our test it gave https://n8n.example.com:5812/rest/oauth2-credential/callback. Set WEBHOOK_URL or N8N_EDITOR_BASE_URL to https://your-domain/ instead.
What does "The OAuth callback state is invalid!" mean?
The sign-in link was already used or is too old. Each Connect my account click creates a one-time link; click it again instead of reloading the callback page.
What does "Insufficient parameters for OAuth2 callback" mean?
The provider came back without an authorization code, usually because the consent screen was cancelled or denied (error=access_denied), or the account isn't allowed, such as a Google app in Testing without that user in its test users.
Related guides
- n8n Gmail node not working: Client authentication failed, invalid_grant, OAuth2 fixes
- n8n Google Drive node not working: Bad request, binary file not found, OAuth2 fixes
- n8n won’t start or you can’t log in? 11 self-hosting errors, tested
- n8n MongoDB node errors: Authentication failed, Invalid JSON and query fixes, 40 runs
- n8n Webhook file upload not working? Binary data keys, 25 tests
New guides
- GitHub release notifications in Slack (any public repo, stable releases only)
- Send RSS feeds to Slack with a keyword filter (free, incoming webhook)
- Forward emails to a Slack channel (Gmail, Outlook, any IMAP), free with an incoming webhook
- n8n Google Sheets Trigger not working: not firing, activation errors and fixes