PassportJS Google登录错误,但成功
问题描述:
当我使用PassportJS和passport-google-oauth20
与Google登录时,我的应用程序成功完成请求,但Passport无法识别此消息,而是调用错误。PassportJS Google登录错误,但成功
我的代码如下所示:
router.get('/auth/google/callback',
passport.authenticate('google', {failureRedirect: '/login'}),
(req, res) => console.log(req),
(err, req, res, next) => {
console.log('test point 1')
console.log(err.stack)
return res.status(500).send(err)
})
输出看起来是这样的,这表明该请求没有失败,我相信:
test point 1
undefined
但是,当我检查我的浏览器,它返回一个500代码与正确的Google用户信息,如配置文件图片和ID。护照不会将它存储在它应该的req.user
变量中。谢谢!
如果它是有用的,我的护照初始化是非常简单而明确:
// TODO: eventually setup user account system
passport.serializeUser((user, done) => done(null, user))
passport.deserializeUser((obj, done) => done(null, obj))
// TODO: eventually use this to associate the users account
passport.use(new GoogleStrategy({
callbackURL: 'http://localhost:8080/api/v0/auth/google/callback',
clientID: 'number-id.apps.googleusercontent.com',
clientSecret: 'secrets'
}, (accessToken, refreshToken, profile, cb) => {
cb(profile)
}))
我能想到的,这将是我的情况唯一不同的是,我在一个特定的只有use
荷兰国际集团护照一组路线。 (例如API)
答
在此行上:cb(profile)
我向回调发送错误而不是用户配置文件。
它应该是这样的:cb(null, profile)
。