Issue with Google OAuth2 Credentials in n8n: "localhost refused to connect"

Hi n8n community,

I’m facing an issue while trying to set up Google OAuth2 credentials in n8n and would appreciate any help or guidance. I’m relatively new to n8n and self-hosting, so step-by-step instructions would be incredibly helpful! Here’s a detailed explanation of the problem:

Setup Details:

  • I’m self-hosting the latest n8n Docker image on Render.com.
  • I’ve followed the official documentation and multiple tutorials to set up Google OAuth2 credentials.
  • My OAuth Redirect URL in the Google Cloud Console is set to:
    http://localhost:5678/rest/oauth2-credential/callback

The Problem:

When I enter my Client ID and Client Secret in the n8n Google Calendar OAuth2 API node and proceed to sign in to my Google account, I:

  1. Select my Google account.
  2. Grant all the required permissions.
  3. Click “Allow.”

At this point, instead of being redirected back to n8n, I’m taken to a page with the following error:
This site can’t be reached localhost refused to connect. ERR_CONNECTION_REFUSED

What I’ve Tried:

  • Verified the OAuth Redirect URL multiple times to ensure it matches the one in the Google Cloud Console.
  • Confirmed that the n8n instance is running and accessible.
  • Checked for any proxy or firewall issues but didn’t find anything blocking the connection.

Additional Context:

  • I’m using Render.com to host n8n, and the instance is running without any other apparent issues.
  • I’m not using a custom domain or any reverse proxies (e.g., Nginx, Traefik).
  • I’ve double-checked the Google Cloud Console settings (e.g., authorized domains, redirect URIs) to ensure they align with the documentation.

Since I’m a complete noob to n8n and self-hosting, I’d really appreciate it if someone could guide me step-by-step to resolve this issue.

If any additional information would help diagnose the issue, please let me know, and I’ll provide it.

Thanks in advance for your help!

Localhost isn’t reachable from the internet - when Google tries to connect to it, their servers connect to themselves. You need to set up n8n on a fully qualified domain name.

4 Likes

Thanks man, Problem solved.

4 Likes

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