我在快递中使用以下代码与护照:
var GAuth = require('passport-google-oauth');
passport.use('google', new GAuth.OAuth2Strategy({
clientID: GID,
clientSecret: GSECRET,
callbackURL: "http://localhost:3000/auth/google/callback"
},
function(accessToken, refreshToken, profile, done){ // not running
console.log('callback');
console.log('id: ', profile.id);
}));
router.get('/google', passport.authenticate('google', {
scope: [
'email',
'profile'
]
}));
router.get('/google/callback', function(req, res) { // this runs
res.send('Logged in through Google!');
});
即使登录在外部看起来工作正常,我也可以转到google的权限页面,然后转到回调页面。我无法运行回调函数,所以我做错了什么?
答案 0 :(得分:1)
你的路由器中是否应该为“/ auth / google / callback”定义一个POST?
答案 1 :(得分:1)
router.get('/google/callback',
passport.authenticate('google', {
successRedirect : '/home',
failureRedirect : '/'
})
);
这应该有用。