Google Drive OAuth2 API

Describe the problem/error/question

Hello.

I have successfully been able to setup authentication Google Drive OAuth2 API for two clients using their Google Workspace accounts. However, when I am trying to do the same using my personal account I am running into issues.

What is the error message (if any)?

I keep getting the following error:

You can’t sign in because this app sent an invalid request. You can try again later, or contact the developer about this issue. Learn more about this error

If you are a developer of this app, see error details.

Error 400: redirect_uri_mismatch

However, I have copied the redirect url exactly: https://oauth.n8n.cloud/oauth2/callback

I believe that the issue is that personal accounts seem to need additional setup that may or may not be supported?

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 2.1.1
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): n8n cloud
  • Operating system:
1 Like

Hi @acoodledoo

This is a very common Google OAuth2 gotcha, and you’re on the right track: the difference is not Workspace vs personal accounts, but how the OAuth client is configured and published.

Error 400: redirect_uri_mismatch means Google does not see an exact match between the redirect URI sent in the OAuth request and the redirect URI registered in the Google Cloud Console for that specific OAuth client.

Even a single difference (scheme, trailing slash, encoding, client type) will cause this.

Google Workspace accounts often “appear to work” because they are internal apps and they bypass some OAuth verification and publishing restrictions. But Personal (consumer) accounts are much stricter.

We will recommend checking OAuth Consent Screen, it must be External.

For personal accounts, this is mandatory.

Go to APIs & Services → OAuth consent screen

Ensure User type: External - Publishing status: In testing or Published

If “In testing”, you MUST add your personal Gmail under Test users.

thank you for the reply @bridgewaretech

i have copied the redirect url exactly: https://oauth.n8n.cloud/oauth2/callback

  • user type: external
  • publishing status: in production

however even with all of that configured i still get the same error.

I’m having the same issue I get a popup when I click sign in. I’ve tried literally everything. I just made a post about this also. Seems to be an ongoing bug with N8N. I think they need to switch it so the redirect URL starts with https:// instead of having to hard code it. From What i can see it auto routes to the domain not the url, and I beleive that’s the root of the issue.

I am having the same issue. I tried everything and followed the tutorial exactly.
Having a cloud subscription it seems there is a mismatch between the URI proposed by to use by N8N (https://oauth.n8n.cloud/oauth2/callback) and the one actually used in the connection between Google and N8N (https://”personal instance”.n8n.cloud/rest/oauth2-credential/callback)

Honestly, it feels like a bit of a mess

Hi All,

We are running n8n self-hosted, where this Google OAuth setup works correctly and the issue is not present.
Because of this, unfortunately we can’t fully verify or rule out problems specific to n8n Cloud–hosted instances, and it’s possible this is related to n8n Cloud’s OAuth configuration rather than your Google setup.

That said, we would suggest checking also the following. If all of the following checks are still not making any difference, we recommend raising a bug report so the n8n team can provide further help.

  • OAuth Client type

    • Must be Web application

    • Desktop / Native clients will fail with this redirect URI

  • Correct OAuth Client ID

    • n8n must be using the same Client ID where the redirect URI is configured

    • Double-check there isn’t another OAuth client in the project with a similar name

  • Correct Google Cloud project

    • The OAuth client and the OAuth consent screen must belong to the same project

    • Redirect URIs do not carry over between projects

  • Authorized redirect URIs vs Authorized JavaScript origins

    • The URL must be added under Authorized redirect URIs

    • Adding it under JavaScript origins does not work

  • Propagation / cache

    • Wait 5–10 minutes after changes

    • Retry in an incognito window or different browser

2 Likes

Hi @acoodledoo :waving_hand: , does it work if using https://your-instance.n8n.cloud/rest/oauth2-credential/callback (replace your-instance with the name of your instance that you see in your browser) ? It’s possible that the callback url displayed in the UI is a wrong one

This issue seems to have been fixed already: Google OAuth redirect_uri_mismatch on n8n Cloud on Google Docs, Drive, Calendar... · Issue #23568 · n8n-io/n8n · GitHub

We have released version 2.1.4 which fixes all issues with OAuth - please make sure your n8n Cloud instances are on that version. The beta version 2.2.1 has been removed from Cloud until we patch that as well, which will happen after the holidays.

Please accept our apologies for the interruptions and happy holidays to everyone celebrating!

I’m getting the same Error 400: redirect_uri_mismatch. I’m only exposing /webhooks to the public internet and configured everything exactly as described in the docs.

In n8n, the OAuth Redirect URL is fixed and can’t be changed:

https://long-secret-url.ngrok-paid.com/rest/oauth2-credential/callback

Since this URL isn’t reachable from the public internet, I think that’s the problem. Is there any workaround? I really don’t want to expose /rest publicly.

I also tried what someone suggested:
https://localhost:5678/rest/oauth2-credential/callback

However, I can configure this URL only in the Google Console, not in n8n itself, so it didn’t help.