I’m trying to connect a Google OAuth2 API credential in n8n Cloud to access Gmail, but I keep getting an “OAuth callback state is invalid” error (sometimes also “redirect_uri_mismatch”). I’ve tried everything I can think of and need help.
n8n Cloud instance: (username).app.n8n.cloud
- Credential type: Google OAuth2 API
- Google Cloud Project: Fresh project created specifically for n8n
- Gmail API: Enabled
- OAuth consent screen: Configured with my email as a test user
What I’ve Configured:
In Google Cloud Console:
-
Created OAuth 2.0 Client ID (Web application type)
-
Authorized redirect URIs:
-
https://oauth.n8n.cloud/oauth2/callback -
https://(username).app.n8n.cloud/rest/oauth2-credential/callback
-
-
Added required Gmail scopes to OAuth consent screen
-
Client ID and Secret correctly copied to n8n
In n8n:
-
Using the OAuth Redirect URL shown:
https://oauth.n8n.cloud/oauth2/callback -
Client ID and Secret match the Google Console credentials
-
Scope:
https://www.googleapis.com/auth/gmail.send https://www.googleapis.com/auth/gmail.readonly
The Problem:
-
I click “Sign in with Google” in n8n
-
Google’s OAuth consent screen appears ✓
-
I grant permissions ✓
-
After clicking “Allow”, I get redirected to a callback page with error:
Error: The OAuth callback state is invalid!
Failed to connect. The window can be closed now.
Sometimes I also see:
{"error":"redirect_uri_mismatch","error_description":"Bad Request"}
What I’ve Already Tried:
-
Created a completely new OAuth client in Google Console
-
Verified redirect URIs match exactly (no typos, trailing slashes, etc.)
-
Waited 10+ minutes after saving changes in Google Console
-
Deleted and recreated the credential in n8n multiple times
-
Cleared all browser cookies and cache
-
Tried in multiple browsers (Chrome, Firefox, Edge)
-
Tried in incognito/private mode
-
Verified Gmail API is enabled
-
Confirmed my email is added as test user in OAuth consent screen
-
Tried different scope combinations
-
Checked system clock is synchronized
Browser Console Details:
When I check the Network tab in browser dev tools, the callback request returns:
-
Status: 200 (success)
-
Response body shows:
Error: The OAuth callback state is invalid!
Questions:
-
Is there a known issue with n8n Cloud’s OAuth proxy (
oauth.n8n.cloud) for Google OAuth2? -
Should I be using a different credential type for Gmail access?
-
Are there any server-side logs you can check for my instance?
-
Is there an alternative authentication method I should use instead?
Workaround Needed:
I’m happy to use app passwords or service accounts if OAuth isn’t working, but I’d prefer to get OAuth working if possible. Any help would be greatly appreciated!