Passport-facebook возвращает только «id» и «displayName» - PullRequest
0 голосов
/ 05 мая 2018

Я использую passport-facebook для аутентификации пользователей. После аутентификации я получаю только параметры «id» и «displayName». Все остальные поля возвращаются как неопределенные. Я особенно заинтересован в электронной почте. Я не вижу, что вернулся в профиле вообще. Цени любую помощь в выяснении того, что мне не хватает.

конфиг / auth.js:

module.exports = {

    'facebookAuth' : {
        clientID: 'MY_CLIENT_ID', // your App ID
        clientSecret: 'MY_CLIENT_SECRET', // your App Secret
        callbackURL: '/auth/facebook/callback',
        profileFields: ['id', 'emails', 'displayName']
    },

Я также попытался изменить «электронные письма» на «электронные письма»

Маршруты:

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

Стратегия Facebook:

passport.use(new FacebookStrategy({
    clientID        : configAuth.facebookAuth.clientID,
    clientSecret    : configAuth.facebookAuth.clientSecret,
    callbackURL     : configAuth.facebookAuth.callbackURL
},

function(token, refreshToken, profile, done) {
    process.nextTick(function() {
        console.log(util.inspect(profile, {showHidden: false, depth: null}))
        User.findOne({ 'facebook.id' : profile.id }, function(err, user) {
            if (err)
                return done(err);

            if (user) {
                return done(null, user); // user found, return that user
            } else {
                // if there is no user found with that facebook id, create them
                var newUser            = new User();

                newUser.facebook.id    = profile.id; // set the users facebook id
                newUser.facebook.token = token; // we will save the token that facebook provides to the user
                newUser.facebook.name  = profile.displayName; // look at the passport user profile to see how names are returned
                // newUser.facebook.email = profile.emails[0].value; // facebook can return multiple emails so we'll take the first

                // save our user to the database
                newUser.save(function(err) {
                    if (err)
                        throw err;

                    // if successful, return the new user
                    return done(null, newUser);
                });
            }

        });
    });

}));

Возвращена информация профиля:

GET /auth/facebook 302 0.744 ms - 0
{ id: '10156351538257640',
  username: undefined,
  displayName: 'Nitin Vig',
  name: 
   { familyName: undefined,
     givenName: undefined,
     middleName: undefined },
  gender: undefined,
  profileUrl: undefined,
  provider: 'facebook',
  _raw: '{"name":"Nitin Vig","id":"10156351538257640"}',
  _json: { name: 'Nitin Vig', id: '10156351538257640' } }
GET /auth/facebook/callback?code=AQAdi8Gs55Th1oXVXGLxNynm8s_rYs9XWC7IRB4hCk5xoVWCgPsRXS-DL6Q6ekI0bvb5osls77OWSfuTdCAIhkc2ntohRrG6ZDES3Nx907FdpjMzJzfCYJfXYeutBAkPwTbesjdcBsig_76VFWwV9WL-6X0jLngTtYLdkELWid9G5bTltc0HrmUEaVkf8w6LeaDHdbQ1tlxh5CP9P9W7vT_M6AVXSpGPFTaoLI8IO25jyS-Xm9bIprPQV1-eVYK_EHhcYZVaK2INnGeWhwTu-6P1MMFO4gPIFGgiKqSmREXnfS4C_JqgwpjEc0Z5PGbhLIE 302 16582.309 ms - 60
GET /profile 200 2.081 ms - 2204

Я использую аналогичный код с passport-google-oauth, и он отлично работает.

...