Connectivity issue

I’m trying to set up an automation to get google sheet rows from n8n. I’ve configured Google OAuth2 correctly, and the Google login process completes successfully. But at the final step, after Google redirects back,
I get this error: “This site can’t be reached — localhost refused to connect”
I run Docker on Mac.

Hello and welcome to the community, @supriya
Does your Redirect URL have localhost in it?

yes, it does, I did add the call back local host id to the OAuth as welll in Google console

Well this is your problem then. “localhost” for a server trying to access it means “me”, Redirect URL is used to redirect you back to your n8n instance within the OAuth process, so when you give Google Authorization server a localhost url, it means you are it to redirect the request back to itself, and Google Authorization server does not host your n8n, so it refuses to connect.

Redirect URL should be a public (or otherwise reachable) url, to send you back to n8n.

Thank you, how can I make thr=e above local host as public?

http://localhost:5678/rest/oauth2-credential/callback

Hey @supriya

You can use cloudflare with a domain name 🔐 How I Secured My n8n Instance with Cloudflare Zero Trust (No Open Ports, No Public IP) further edits to come

Or some people use ngrok for temporary URL etc.

The main part for n8n is

  - N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
  - WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
  - N8N_PROTOCOL=https

Hope this helps,

Samuel

Supriya,

Here is a step by step video on how to do this. https://youtu.be/ZM9w2SvSzV4?si=KhYn107Lt9C_kOPC

Text instructions as follows
When you run n8n locally (usually on port 5678), only your own computer can access it. If you want to share your n8n instance with others or connect it to webhooks/services that need a public URL, you’ll need to expose it online. ngrok is a free tool that creates a secure, public link to your local server.

How to Expose n8n (Docker, Port 5678) with ngrok

1. Make sure n8n is running in Docker on port 5678

If you haven’t already, start n8n with:

bash

docker run -it --rm --name n8n -p 5678:5678 -v ~/.n8n:/home/node/.n8n n8nio/n8n

This maps your local port 5678 to the container’s port 56787.

2. Install ngrok

  • Download ngrok from ngrok.com/download and install it for your OS.
  • (Optional but recommended) Sign up for a free ngrok account, get your auth token, and run:

bash

ngrok config add-authtoken <YOUR_AUTH_TOKEN>

3. Start ngrok for your n8n port

Run:

bash

ngrok http 5678

This will give you a public URL (e.g., https://abcd1234.ngrok.io) that anyone can use to access your local n8n editor7.

4. Share the ngrok URL

  • Use this public URL for webhooks or to let others access your n8n instance.

Let me know if you need screenshots or run into any issues!