我面临一个奇怪的问题,我的应用程序是使用用户的fb凭据登录但我无法看到他的电子邮件,名称或ID等。这是我在users.js路由中所做的事情: -
router.get('/auth/facebook',passport.authenticate('facebook', {scope: ['email', 'user_friends']}));
router.get('/auth/facebook/callback',
passport.authenticate('facebook',{ successRedirect:'/profile',failureRedirect:'/'},function(req,res){
console.log("in passport req"); //doesn't get printed
console.log(req);
}));
在我的config / passport.js中我正在做: -
var configAuth=require('./auth'); //holds all appID, secret and successurl
var FacebookStrategy=require('passport-facebook').Strategy;
var passport=require('passport');
module.exports=function(passport){
passport.use(new FacebookStrategy({
clientID: configAuth.facebookAuth.clientID,
clientSecret: configAuth.facebookAuth.clientSecret,
callbackURL: configAuth.facebookAuth.callbackURL,
profileFields: ['id', 'displayName', 'photos', 'email']
},
function(accessToken, refreshToken, profile, cb) {
console.log("the user's credentials are: "); //doesn't get printed
console.log(profile.user);
}
));
};
一切都工作正常我被重定向到successURL但我怎么能得到用户信息的原因没有它一切都是徒劳的,任何帮助将不胜感激。控制台中没有错误。
答案 0 :(得分:4)
检查req.user
app.get('login',
passport.authenticate('facebook', {
failureRedirect:'/'
}),
function(req, res, next){
//check req.user
console.log('user should be',req.user);
res.redirect('/profile')
});