Monday, 5 June 2017

Custom Callback never called when Google Auth on passportjs

I try to login with Google by using PassportJS. But when I use the custom callback, the Google Strategy never called the callback. What am I doing wrong? My codes are below.

endpoints:

var router = express.Router();
router.get('/',
  passport.authenticate('google', { scope: [
    'https://www.googleapis.com/auth/plus.login',
    'https://www.googleapis.com/auth/plus.profiles.read',
    'https://www.googleapis.com/auth/userinfo.email'
  ] }
));

router.get('/callback', function (req, res) {
  console.log("GOOGLE CALLBACK");
  passport.authenticate('google', function (err, profile, info) {
    console.log("PROFILE: ", profile);
  });
});

module.exports = router;

Passport:

passport.use(new GoogleStrategy({
          clientID: config.GOOGLE.CLIENT_ID,
          clientSecret: config.GOOGLE.CLIENT_SECRET,
          callbackURL: config.redirectURL+"/auth/google/callback",
          passReqToCallback: true
          },
          function(request, accessToken, refreshToken, profile, done) {
            process.nextTick(function () {
              return done(null, profile);
            });
          }
        ));

GOOGLE CALLBACK log is printed but PROFILE log never printed.

Thanks in advance.



via endrcn

No comments:

Post a Comment