shashwat12
shashwat12

Reputation: 168

OAuth Google callback throws error "connection attempt to localhost was rejected"

I am new to node.js and I was trying to implement OAuth 2.0 with Google using passport.js.

I have my clientID , clientSecret and Authorized Redirect URLs from Google Developer Console. The callback URL is something like http://localhost:portNumber/foo/bar/callback and the application works perfectly when I run it from my machine.

The problem occurs when I try to access it over the Internet using a Public IP Address. I am able to access my website but as soon as I allow my application to access my Google+ profile using OAuth it gives an error connection attempt to localhost was rejected. It gives an ERR_CONNECTION_REFUSED error for my callback URL.

I am stuck as I do not have a domain right now to use instead of localhost.

Kindly excuse me if my question is vague and any help would be appreciated.

P.S : I have forwarded my port.

Upvotes: 2

Views: 1644

Answers (1)

simo
simo

Reputation: 15478

As suggested in my comment from above you can use localtunnel.me:

  1. Install the localtunnel module on your workstation: npm install -g localtunnel
  2. Run you web server as usual: node app.js
  3. Run tunnel for your web server: lt --port 3000 (3000 is the port your server listens to)
  4. After you run the tunnel from above you will receive a URL in return: https://glsjjuobon.localtunnel.me (glsjjuobon is a randomly generated string)
  5. Use the above URL to add additional Authorized Redirect URI in the Google's developer console for your project: https://glsjjuobon.localtunnel.me/connect/google/callback

That's it! As long as your local server and the tunnel are both running you can use the generated URL from localtunnel to access your web site.

Upvotes: 1

Related Questions