OAuth Redirect Fails, Returns 200 OK with HTML instead of 302

Hello,

I’m having a persistent issue with my self-hosted n8n where Google OAuth2 authentication fails. Instead of redirecting to Google (302 Found), the request to /rest/oauth2-credential/auth returns a 200 OK with the n8n editor’s HTML, resulting in a blank popup.

My Environment:

  • n8n: Self-hosted via Docker.
  • Proxy: Apache2 reverse proxy with SSL termination.
  • URL: https://n8n.domain.com

Things I have definitively ruled out:

  1. Reverse Proxy: The issue persists even when bypassing Apache and connecting directly to the n8n container’s exposed port. The correct RequestHeader set X-Forwarded-Proto "https" directive is in place.
  2. n8n Version: The issue occurs on multiple versions, including 1.100.1, 1.90.2, and :stable.
  3. Data Corruption: The issue occurs even when starting n8n with a completely fresh, empty volume (both for the .n8n directory and a clean SQLite database).
  4. Browser Cache: The issue persists in Incognito/Private browser windows.
  5. Google Credential: The issue persists even after deleting the old OAuth Client ID and creating a brand new one from scratch.
  6. Google Cloud URIs: I have verified that my Authorized JavaScript origins and Authorized redirect URIs are correct.
  • Origins: https://n8n.domain.com
  • Redirect URIs: https://n8n.domain.com/rest/oauth2-credential/callback

My docker-compose.yml for the proxied setup is:

services:
  n8n:
    image: n8nio/n8n:stable
    container_name: n8n
    restart: always
    ports:
      - "127.0.0.1:5678:5678"
    environment:
      N8N_PROTOCOL: https
      N8N_HOST: n8n.domain.com
      WEBHOOK_URL: https://n8n.domain.com/
    volumes:
      - ~/.n8n:/home/node/.n8n

I am looking for any non-standard causes, as all standard troubleshooting has failed. Any ideas would be greatly appreciated.

You are running apache on https, but not n8n. I don’t think you should have N8N_PROTOCOL set to https. The docs say that is to be set to “The protocol used to reach n8n.” which is a bit ambiguous, but I’m pretty sure that tells the runtime to expect https connections in the n8n node.js app listener. Try removing that and remake the container, and verify it is gone after restarting the container (docker exec -ti n8n env). FWIW, every properly functioning instance of n8n I have running behind Traefik (as an https-terminating-reverse-proxy) is configured with N8N_PROTOCOL=http

The N8N_HOST setting might also be dorking things up since that’s the same hostname you have configured to route to Apache. Try also setting that to an “internal” hostname like n8n.

Thank you, I was able to resolve this! It was caused by the ModSecurity module in Apache.