-
Notifications
You must be signed in to change notification settings - Fork 662
Open
Description
This is my Google OAuth 2.0 passport option:
options: {
clientID: 'my-client-id'
clientSecret: 'my-client-secret',
callbackURL: '/api/auth/google/callback',
scope: [ 'profile', 'email' ],
passReqToCallback: true,
state: true
}
Here's my Google passport strategy:
var passport = require('passport');
var GoogleStrategy = require('passport-google-oauth20').Strategy;
var User = require('@models/user');
var config = require('@config');
passport.use(new GoogleStrategy({
clientID: config.googleClientId,
clientSecret: config.googleClientSecret,
callbackURL: config.googleCallbackUrl,
scope: ['profile', 'email'],
passReqToCallback: true,
state: true,
},
function(req, accessToken, refreshToken, profile, done) {
console.log('profile: ', profile);
try {
var searchQuery = {
name: profile.displayName
};
// store user info in mongo
User.findOne(searchQuery, function(err, user) {
if(err) {
console.log('[google] err: ', err);
return done(err);
} else if (user !== null) {
console.log('google user already there');
return done(null, user);
}
console.log("user not present, creating one...");
user = new User({
name: profile.displayName,
email: profile['_json']['email'],
profileId: profile.id,
google: {
accessToken,
profileId: profile.id,
email: profile['_json']['email']
}
});
user.save(function(err) {
if(err) {
console.log('err occurred while saving google user: ', err);
console.log(err); // handle errors!
} else {
console.log("saving user ...");
}
});
});
} catch (verifyErr) {
done(verifyErr);
}
}
));
module.exports = passport;
I've checked by logging the values in passport-oauth2 and passport-google-oauth20. Here's what I found:
- The execution is going here with everything as expected (profile contains the expected data)
- The control then goes to my passport google strategy file (mentioned above). Profile and access token being correct here as well.
- But the issue is happening right after the above step, the execution is going right to the Strategy.userProfile function and the err block having the message of CONNRESET
- This leads me to this error and the server exits. All the server code is exactly the same for github oauth but it works without any errors. This makes me think there's some issue with google's OAuth package?
Opening the issue here because the issue can also be in the request implementation and related to keep-alive timeout?
Metadata
Metadata
Assignees
Labels
No labels