我在passport中使用了以下代码:
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的权限页面,然后被定向到回调页面。我不能让回调函数运行,那么我做错了什么?
发布于 2015-06-25 07:31:37
你不应该在路由器中为"/auth/google/callback“定义一个POST吗?
发布于 2015-10-27 06:07:26
router.get('/google/callback',
passport.authenticate('google', {
successRedirect : '/home',
failureRedirect : '/'
})
);这应该是可行的。
https://stackoverflow.com/questions/31038394
复制相似问题