无法使用护照快速找到用户的凭据
Can't find user's credentials in express using passport
我遇到了一个奇怪的问题,我的应用程序是使用用户的 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 但我如何才能获得用户信息因为没有它一切都是徒劳的,任何帮助将不胜感激。控制台没有错误。
检查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')
});
我遇到了一个奇怪的问题,我的应用程序是使用用户的 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 但我如何才能获得用户信息因为没有它一切都是徒劳的,任何帮助将不胜感激。控制台没有错误。
检查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')
});