Skip to content

500 failed to obtain access token (Error: connect ECONNREFUSED) #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
rajolichandra opened this issue Nov 7, 2014 · 5 comments
Open

Comments

@rajolichandra
Copy link

No description provided.

@rajolichandra
Copy link
Author

500 failed to obtain access token (Error: connect ECONNREFUSED)
at D:\Chandrasekhar\NodeJs_Workspace\SkillsetMgmtNode\node_modules\passport-google-oauth\node_modules\passport-oauth\lib\passport-oauth\strategies\oauth2.js:125:38
at D:\Chandrasekhar\NodeJs_Workspace\SkillsetMgmtNode\node_modules\passport-google-oauth\node_modules\passport-oauth\node_modules\oauth\lib\oauth2.js:177:18
at ClientRequest. (D:\Chandrasekhar\NodeJs_Workspace\SkillsetMgmtNode\node_modules\passport-google-oauth\node_modules\passport-oauth\node_modules\oauth\lib\oauth2.js:148:5)
at ClientRequest.emit (events.js:95:17)
at CleartextStream.socketErrorListener (http.js:1547:9)
at CleartextStream.emit (events.js:95:17)
at Socket.onerror (tls.js:1440:17)
at Socket.emit (events.js:117:20)
at net.js:440:14
at process._tickCallback (node.js:419:13)

PassportJs Code

app.get('/auth/google', passport.authenticate('google', { session: false,
accessType: 'offline',
approvalPrompt: 'force' }));

passport.use(new GoogleOAuth2Strategy({
clientID : configAuth.googleAuth.clientID,
clientSecret: configAuth.googleAuth.clientSecret,
callbackURL: configAuth.googleAuth.callbackURL,
scope: ['profile', 'email', 'openid'],
passReqToCallback : true
},

function(accessToken, refreshToken, profile, done) {
    console.log(params.expires_in);
    console.log(profile.id);
    process.nextTick(function() {           
        // try to find the user based on their google id
        User.findOne({ 'google.id' : profile.id }, function(err, user) {
            if (err)
                return done(err);

            if (user) {
                // if a user is found, log them in
                return done(null, user);
            } else {
                // if the user isnt in our database, create a new user
                var newUser          = new User();

                // set all of the relevant information
                newUser.google.id    = profile.id;
                newUser.google.token = accessToken;
                newUser.name = profile.displayName;
                newUser.google.name  = profile.displayName;
                newUser.google.email = profile.emails[0].value; // pull the first email

                console.log(profile.id);
                console.log(accessToken);
                console.log(profile.displayName);
                console.log(profile.emails[0].value);

                // save the user
                newUser.save(function(err) {
                    if (err)
                        throw err;
                    return done(null, newUser);
                });
            }
        });
    });

})); 

@rajolichandra
Copy link
Author

Hi,

Can you please provide the solution for the above issue ??

@kalinichenko
Copy link

I ran into the same problem and in my case using a proxy server caused a problem. To be more specific an error was occurred doing a POST to https://accounts.google.com/o/oauth2/token
glad if it helps.

@sourav2029
Copy link

sourav2029 commented Jun 27, 2016

As @kalinichenko mentioned , the error is because you are behind a proxy , Try running it without proxy . Hope it should work beacause it worked for me .

@netpoetica
Copy link

@jaredhanson What is the appropriate path for making sure that the solution to this problem isn't just "don't use a proxy"? I don't think the issue will be able to be solved in the light layer of passport - it's much deeper in the oauth lib. Just as an FYI there is a PR here for it: ciaranj/node-oauth#294

Maybe with a request coming from you, the author of oauth lib will consider merging this PR, which will allow you to close this open issue. I'm quite certain every other passportjs plugin/strategy has the exact same problem though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants