Lorixen.
EN

n8n Google Sheets Credential: Fixing 'redirect_uri_mismatch' and Access Errors

Short answer: The error redirect_uri_mismatch means the callback address n8n sends to Google is not exactly one of the authorised redirect URIs in your Google Cloud OAuth client. Copy the OAuth Redirect URL shown inside the n8n credential window, paste it character for character into the OAuth client's authorised redirect URIs, and make sure n8n knows its public address when it runs behind a proxy, otherwise it will offer a localhost or http URL. "Access blocked" errors come from the consent screen instead: add your Google account as a test user or publish the app, and enable the Sheets and Drive APIs. If you only need one or two spreadsheets, a non-human Google identity with a key file skips the OAuth dance entirely.

Why the mismatch happens

When you press the Google login button inside an n8n credential, n8n opens Google's login page and tells Google where to send the user afterwards. Google compares that address with the list in your OAuth client. The match is strict: scheme, host, port, path and trailing characters must be identical.

Typical mismatches on self-hosted setups:

  • n8n sends http://localhost:5678/rest/oauth2-credential/callback because it does not know its public domain.
  • n8n sends http:// while Google has https:// registered, because TLS ends at a reverse proxy.
  • A port number such as :5678 appears in one and not the other.
  • The OAuth client was created for a different subdomain, for example a staging instance.

Step 1: Set up the Google Cloud project

If you have not done this yet, or want a clean start:

  1. In Google Cloud Console, create a project, for example "n8n automations".
  2. In the API library of that project, enable the Google Sheets API and the Google Drive API. n8n uses Drive to list and find spreadsheets, so missing Drive access causes confusing errors later.
  3. Configure the OAuth consent screen. For a company Google Workspace account where only colleagues will connect, choose the internal user type if it is offered. Otherwise choose external.
  4. Create credentials of type OAuth client ID, application type Web application.

Leave the redirect URI empty for a moment; you will copy it from n8n.

Step 2: Copy the exact redirect URL from n8n

In n8n, create a new credential of type Google Sheets OAuth2 API (or the general Google OAuth2 credential if you need several Google services). The credential window displays an OAuth Redirect URL field with a copy button.

Look at that value before copying it:

  • Does it show your real public domain, such as https://automations.example.com/...?
  • Is it https?
  • Is the path /rest/oauth2-credential/callback?

If all three look right, paste it into the Google OAuth client under Authorised redirect URIs and save. Copy the client ID and client secret back into n8n, then click the sign-in button. Google can take a few minutes to apply changes to the client, so wait briefly if the first try still fails.

If the URL shows localhost or http, fix n8n first (next step). Registering the wrong URL in Google might appear to work from your own machine but will break for anyone else.

Step 3: Fix the host settings behind a proxy

Most self-hosted n8n instances sit behind Nginx, Caddy, Traefik or a hosting platform's router. n8n builds its own public URLs from environment variables. The commonly relevant ones are:

Variable Example value Role
N8N_HOST automations.example.com Public hostname
N8N_PROTOCOL https Scheme used in generated URLs
N8N_PORT 5678 Internal port n8n listens on
WEBHOOK_URL https://automations.example.com/ Public base URL for webhooks and callbacks
N8N_EDITOR_BASE_URL https://automations.example.com/ Public URL of the editor

Which variable drives the OAuth callback depends on your n8n version, so check the n8n documentation for the release you run. In practice, setting WEBHOOK_URL and the editor base URL to the full public https address, then restarting the container, fixes most cases. After the restart, open a fresh credential window and confirm the displayed redirect URL changed.

Also check the proxy forwards the original host and protocol headers, and that the n8n setting for trusting the proxy is enabled if your version requires it. Otherwise n8n may still believe requests arrive over plain http.

Once the redirect matches, the next screen may say access is blocked or that the app has not completed verification. That is the consent screen, not n8n.

  • External app in testing status: only accounts listed as test users can authorise. Add the Google account you sign in with under test users.
  • Testing status and token expiry: Google documents that refresh tokens for external apps in testing status expire after a limited period, so the credential may stop working after some days. For a long-running workflow, either use an internal app (Workspace only), publish the app, or switch to the key-file approach in step 5.
  • Publishing an external app: for your own use with the Sheets and Drive scopes, publishing can trigger Google's verification requirements for sensitive scopes. Read Google's current guidance on OAuth 2.0 and app verification before you decide.
  • Workspace admin restrictions: a company admin may block third-party apps. Ask them to allow the OAuth client ID in the Admin console API controls.

Step 5: Skip OAuth for a single spreadsheet

If your workflow writes to a single order log or reads one price list, OAuth may be overkill. Google Cloud lets you create a non-human identity, known as a service account, that authenticates with a downloaded key instead of a browser login.

  1. Inside the same Cloud project, add one under IAM and admin, then download its key in JSON format.
  2. In n8n, choose the Google Service Account credential type and copy across the client email and private key from that file.
  3. Open the spreadsheet, press Share, and add that client email like a colleague, with editor rights if n8n must write.
  4. In the Google Sheets node, pick this credential and select the document by ID or URL.

The trade-off: this identity can only open files explicitly shared to its address, and it never acts on behalf of a person. For a tidy, single-purpose integration that is a feature, not a limitation. Store the key carefully and rotate it if it is ever exposed.

Quick diagnostic checklist

  1. Sheets and Drive APIs enabled in the right project.
  2. OAuth client type is Web application.
  3. Redirect URL in n8n shows the public https domain.
  4. That exact string is in the client's authorised redirect URIs.
  5. Your Google account is a test user, or the app is internal or published.
  6. No Workspace admin block on the client ID.
  7. n8n restarted after changing environment variables.

FAQ

Can we use the same OAuth client for several n8n instances?

Yes, if you add each instance's redirect URL to the same client. Many teams prefer separate clients for production and testing so one cannot break the other.

Why does it work on our laptop but not on the server?

Your local n8n sends a localhost redirect that happens to be registered, while the server sends its own address. Register the server's URL and set its host variables.

Do we need both the Sheets and Drive APIs?

In most setups, yes. Sheets handles reading and writing cells, while Drive is used to search and list files.

Is the key-file approach safe for customer data?

It can be, provided the key is stored securely, access is limited to the sheets that need it, and you treat it like any other system account with access to personal data.

Running n8n for real business processes and want the hosting, credentials and monitoring set up cleanly, reach out to us with your current setup.

Sources

WhatsAppBook a call