我正在尝试使用nodejs为Google登录实施通行证oauth策略。当我在已设置的应用程序上使用Google帐户登录时,服务器控制台将打印我的个人资料详细信息(由Google共享),服务器应将我的信息重定向到个人资料页面。但是,它无法对我进行身份验证,然后返回首页,提示用户未经过身份验证。下面是我的服务器代码:
app.get('/', (req, res) => {
res.json({
status: 'session cookie not set'
});
});
app.get('/auth/google', passport.authenticate('google', {
scope: ['profile']
}));
app.get('/profile',isauthenticated,(req,res)=>{
res.send(req.user);
});
app.get('/api/auth/google/callback',
passport.authenticate('google'),(req,res)=>{
//console.log(req.sessionStore);
res.redirect('/profile');
}
);
function isauthenticated(req, res, next) {
if (req.user) { return next(); }
//console.log(req);
res.redirect('/');
}
也许问题是passport.authenticate('google')
无法正常工作,这就是如果条件永远都不为真的情况下采用'isauthenticated'方法的原因。
请指导我,并告诉我护照的Google策略是否存在错误!