jmreyes / passport-google-id-token

Google ID token authentication strategy for Passport and Node.js.
MIT License
44 stars 22 forks source link

cordova-plugin-googleplus + passport-google-id-token #29

Open publicbar opened 5 years ago

publicbar commented 5 years ago

Hi, I've got client (cordova plugin) logging in ok and getting the idtoken on android device. I then post this to my server (localhost). (req.body.id_token) I get no errors: I tried another plugin that verifies the idtoken and that works.

Code:

passport.use(new GoogleTokenStrategy({ clientID: '123433.apps.googleusercontent.com', getGoogleCerts: null }, function(parsedToken, googleId, done) { console.log(parsedToken); <--------- Never gets here User.findOrCreate({ googleId: googleId }, function (err, user) { return done(err, user); }); } ));

router.post('/auth/google', function(req, res, next){ verifier.verify(req.body.id_token, '1234.apps.googleusercontent.com', function (err, tokenInfo) { if (!err) { // use tokenInfo in here. console.log(tokenInfo); <--gets here OK } }); passport.authenticate('google-id-token', function(req, res){ res.send(req.user? 200 : 401); <-- never gets here. }); });

I stepped into passport/lib/authenticate.js line 81 and code never enters the function below. return function authenticate(req, res, next) {

I believe I'm overlooking something obvious but its taking me a very long time to find out what. Any clues appreciated! Thanks

publicbar commented 5 years ago

No sooner I posted this I found I needed to do this:

passport.authenticate('google-id-token', function(req, res){ res.send(req.user? 200 : 401);

})(req,res,next); <-- HERE