如何获取消息并将其显示在router.post('/ auth')中?
passport.use(new FacebookTokenStrategy({
clientID: 'HIDDEN',
clientSecret: 'HIDDEN'
}, function(accessToken, refreshToken, profile, done) {
console.log(profile);
var user = {id: profile.id, first_name: profile.name[1], last_name: profile.name[0], email: profile.emails[0], profile_picture: profile.photos[0]};
var error = null;
return done(error, user, {message: "HOW TO RETRIEVE THIS MESSAGE!"});
}
));
我试图通过说console.log(req.message)或console.log(req.session.message)来检索此消息,我只是不知道如何获取它。我也尝试过console.log(req.session.passport.message)
router.post('/auth', passport.authenticate('facebook-token'), function(req, res){
console.log("Verifying");
console.log("HOW TO LOG THAT MESSAGE HERE?");
if(req.isAuthenticated()){
console.log(req.session.passport.user);
}else{
console.log("NOT");
}
});
答案 0 :(得分:0)
如果身份验证成功,我不认为第三个参数会以任何方式传递(在您的情况下总是如此;默认情况下,Passport将在身份验证失败时返回401,并且您的处理程序不会完全被召唤。)
但是,如果您将策略配置为将其传递给验证回调,则可以向req
添加额外的属性:
passport.use(new FacebookTokenStrategy({
clientID: 'HIDDEN',
clientSecret: 'HIDDEN',
passReqToCallback : true,
}, function(req, accessToken, refreshToken, profile, done) {
req.message = 'Your Message Here';
...
}
}))
然后在您的处理程序中,您也可以将其作为req.message
访问。