Skip to content
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

Getting ECONNRESET in passport-google-oauth20 strategy #368

Open
Rishabh570 opened this issue Apr 30, 2022 · 0 comments
Open

Getting ECONNRESET in passport-google-oauth20 strategy #368

Rishabh570 opened this issue Apr 30, 2022 · 0 comments

Comments

@Rishabh570
Copy link

Rishabh570 commented Apr 30, 2022

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:

  1. The execution is going here with everything as expected (profile contains the expected data)
  2. The control then goes to my passport google strategy file (mentioned above). Profile and access token being correct here as well.
  3. 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 ECONNRESET Screenshot 2022-04-30 at 18 13 53
  4. 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?

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

1 participant