var fb = {
clientID: 'xxxxxxxxxxxxxxxx',
clientSecret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
callbackURL: 'http://localhost:4268/auth/facebook/callback'
};
var fbCallback = function(accessToken, refreshToken, profile, cb) {
console.log(accessToken, refreshToken, profile);
};
passport.use(new FacebookStrategy(fb, fbCallback));
router.get('/', passport.authenticate('facebook', {scope:"email"}));
router.get('/auth/facebook/callback',function(req, res) {
res.send("logged in");
});
api
的{{1}}文件夹中,当我登录facebook时,我正在使用users.js
。登录后,我希望消息“登录”,但事实并非如此。回调url中是否有任何错误?
答案 0 :(得分:0)
更改
var fb = {
clientID: 'xxxxxxxxxxxxxxxx',
clientSecret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
callbackURL: 'http://localhost:4268/auth/facebook/callback'
};
var fbCallback = function(accessToken, refreshToken, profile, cb) {
console.log(accessToken, refreshToken, profile);
};
要强>
var fb = {
clientID: 'xxxxxxxxxxxxxxxx',
clientSecret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
callbackURL: 'http://localhost:4268/auth/facebook/callback',
profileFields:['id','displayName','emails']
};
var fbCallBack = function(accessToken, refreshToken, profile, done) {
console.log(profile);
var me = new user({
email:profile.emails[0].value,
name:profile.displayName
});
/* save if new */
user.findOne({email:me.email}, function(err, u) {
if(!u) {
me.save(function(err, me) {
if(err) return done(err);
done(null,me);
});
} else {
console.log(u);
done(null, u);
}
});