2
votes

I am using passport GoogleStrategy to authenticate users, but i am getting below error. Can you please help me ?

Code

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


function(token, refreshToken, profile, done) {
    // User.findOne won't fire until we have all our data back from Google 

    process.nextTick(function() {
        console.log(profile.id);
        User.findOne({ 'google.id' : profile.id }, function(err, user) {
            if (err)
                return done(err);
            if (user) {                
                return done(null, user);
            } else {                   
                var newUser          = new User();                  
                newUser.google.id    = profile.id;
                newUser.google.token = token;
                newUser.google.name  = profile.displayName;
                newUser.google.email = profile.emails[0].value;                 
                console.log(profile.id);
                console.log(token);
                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);
                });
            }
        });
    });

Error Log

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)

1
This error looks like it's happening before the code posted here gets executed. The error is happening in oauth2.js on line 177 in ClientRequest (as shown by the stack trace), most likely due to the server you're making a call to being unreachable for some reason. Please post the code that interacts with oauth2 / ClientRequest.jonafato
I am using passport GoogleOAuth2Strategy to authenticate google users.Chandrasekhar Rajoli

1 Answers

0
votes

I too was getting the same error . For me the error was because i was behind a proxy . When run without proxy the code worked fine . So try this once .