Passport-Facebook giving two different facebook Id

无人久伴 提交于 2019-12-24 11:27:30

问题


I tried to implement facebook OAUTH for my applications(Web and Mobile) using Sails.js/Node.js and Mongo as my backend. I wrote a dedicated function to access the endpoints for each app cause the webApp needs a callback URL and the mobile doesn't. My code screenshot is available below. But, I noticed the two gives me two different Facebook id. I am confused, shouldn't the facebookId be unique? I am using these two modules FacebookStrategy = require('passport-facebook').Strategy FacebookTokenStrategy = require('passport-facebook-token').Strategy

WebApp Strategy

passport.use(new FacebookStrategy({
clientID      : facebook.clientID,
clientSecret  : facebook.clientSecret,
profileFields : ['id', 'email', 'last_name', 'first_name', 'gender', 'link', 'verified', 'updated_time', 'timezone', 'age_range'],
passReqToCallback: true
},
function(req, accessToken, refreshToken, profile, done) {
authenticate(req, accessToken, refreshToken, profile, done);
}
));

The authenticate function being pointed at

 var authenticate = function (accessToken, refreshToken, profile, done) {
User.findOne({facebookId: profile.id}).then(function (user){
    if (user) {
        return [user, {accessToken: accessToken, refreshToken: refreshToken}]
    } else {
        var data = {
            facebookId: profile.id,
            firstname: profile._json.first_name,
            lastname: profile._json.last_name,
            email: profile._json.email,
            gender: profile._json.gender,
            fb_profile_url: profile._json.link,
            fb_verified: profile._json.verified,
            fb_updated_time: profile._json.updated_time,
            phonenumber: profile._json.phone
        }
        var userQry = User.create(data);
    }
    return [userQry, {accessToken: accessToken, refreshToken: refreshToken}]
})
.spread(function (user, credentials){
    if (user) {
        return done(null, [user, credentials]);
    } else {
        return done(null, null);
    }
})
.catch(function (err){
    return done(err, null);
});
}

来源:https://stackoverflow.com/questions/32661411/passport-facebook-giving-two-different-facebook-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!