Google unauthorized 401

Describe the problem/error/question

Could someone help me? When I try to authenticate with Google (Google Drive, Sheets, etc.), after selecting what the app can access, I get this error at the end of the process:

{

“status”: “error”,

“message”: “Unauthorized”

}

I entered the URLs correctly in the fields when creating the client ID in Google Cloud. I also created a new Google Cloud project and new credentials.

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version: latest
  • Database (default: SQLite): postresql
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker
  • Operating system: debiab

achamm:

I think this is how it looks for me - I dont know if its accurate but i’m pretty sure thats what happens when your client id doesnt have permission to access the app. Let me know if this works! or Good luck!

This error is pretty common and usually occurs when the client ID you’re using doesn’t have sufficient permissions to access the resource (in this case, Google Drive). This could be due to a few reasons such as misconfigured credentials, incorrect API keys, or not having enough permissions in your project.

Hi @madrian ,

Did you also enable the APIs you need to use? Drive, Sheets, etc

Hi,

I am just trying to use Google Calendar, so I enabled Google Calendar API only:

Based on docs Drive shouldn’t be needed.

API is enabled:

Then client ID and key is set correctly:

I tried both Google Calendar account and Google Account:

Ok, here is my final solution:

Setup:

N8N locked down for maximum security.

Editor accessible only from local subnet.
I only expose /webhooks and /rest to the public via different (ngrok, public address) URL.

Problem:

Google OAuth always returned 401 Unauthorized on /rest/oauth2-credential/callback.

Cause:

OAuth was started from the LAN-only n8n UI, but the callback came back to the public ngrok URL.

OAuth must start and finish on the same hostname.

Fix:

Temporarily expose the full n8n UI via ngrok and start OAuth from there.
Working Caddyfile (temporary):
:8080 {
reverse_proxy http://n8n:5678 {
header_up Host {host}
header_up X-Forwarded-Proto {scheme}
header_up X-Forwarded-Host {host}
}
}

1 Like

Setting N8N_SKIP_AUTH_ON_OAUTH_CALLBACK=true immediately resolved the Unauthorized OAuth callback issue for me on n8n v2. This appears to be a regression in the internal auth/session validation during OAuth callbacks.

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.