gpt4 book ai didi

javascript - 没有收到来自 Facebook OAuth API 的电子邮件,带有 MEAN Stack 的 Passport

转载 作者:行者123 更新时间:2023-11-29 10:39:25 24 4
gpt4 key购买 nike

我正在努力为用户登录我的网站设置 Face book OAuth。我正在从 Facebook 取回一个包含我的 FB 信息的对象,但在该配置文件响应中的任何地方都没有电子邮件的迹象。

当我点击我页面上的“登录 Facebook”按钮时,它会将我带到 Facebook,并说该应用程序将需要我的个人资料和电子邮件,因为我将电子邮件添加到了我想要的范围内。这是我的代码:

配置/routes.js:

app.get('/auth/facebook', passport.authenticate('facebook', {scope:['email']}));

app.get('/auth/facebook/callback',
passport.authenticate('facebook',
{ successRedirect: '/confirm_community',
failureRedirect: '/signin' }));

============== Passport .js

 passport.use(new FacebookStrategy({
// pull in our app id and secret from our auth.js file
clientID : configAuth.facebookAuth.clientID,
clientSecret : configAuth.facebookAuth.clientSecret,
callbackURL : configAuth.facebookAuth.callbackURL

},

function(accessToken, refreshToken, profile, done) {
process.nextTick(function() {
console.log(profile);
// console.log(profile.emails[0].value);
User.findOne({'facebook.id':profile.id}, function (error, result){
if(error){
return done(error);
}
if(user) {
return done(null, user);
}
else {
var newUser = new User();
newUser.facebook.id = profile.id;
newUser.facebook.token = accessToken;
newUser.facebook.name = profile.displayName;
newUser.facebook.email = profile.emails[0].value;

newUser.save(function (error){
if(error){
console.log(error);
throw error;
} else {
return done(null, newUser);
}
});
}
});
});
}));

这是我在 process.nextTick 函数中使用 console.log(profile) 返回的 FB 对象以及 FB 的响应:

{ id: 'my id is coming back here',
username: undefined, (because I don't have one)
displayName: 'my name is coming back here',
name:
{ familyName: undefined, (I don't have any of these in my profile)
givenName: undefined,
middleName: undefined },
gender: undefined,
profileUrl: undefined,
provider: 'facebook',
_raw: '{"name":"my name is coming here","id":"my id is coming here"}',
_json: { name: 'my name is coming here', id: 'my id is coming here' } }

我确保我的电子邮件是公开的,并使用我的电子邮件和密码正常登录 Facebook,所以我没有使用手机登录 Facebook。我只是缺少那个电子邮件地址。我似乎无法弄清楚为什么那个对象不给我回电子邮件?我错过了什么?非常感谢您的帮助。

最佳答案

我通过 PASSPORT-FACEBOOK 节点模块找到了针对此问题的另一种解决方案。希望这会帮助其他人。

passport.use(new FacebookStrategy({
clientID: FACEBOOK_APP_ID,
clientSecret: FACEBOOK_APP_SECRET,
callbackURL: "http://localhost:3000/auth/facebook/callback",
profileFields: ['email']

引用:https://github.com/jaredhanson/passport-facebook/issues/129

关于javascript - 没有收到来自 Facebook OAuth API 的电子邮件,带有 MEAN Stack 的 Passport,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31640811/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com