passport-facebook: User email is NOT returned from facebook signup

Hi,

We use nodejs with passport-facebook for user to signup account with fb account. Recently we found that the passport-facebook is not returning the email. Anyone has the idea?

We have already defined the fields

    passport.use('facebook', new FacebookStrategy({
        clientID: fb.clientID,
        clientSecret: fb.clientSecret,
        callbackURL: fb.callbackURL,
        profileFields: ['id', 'email', 'name']
     }, function(accessToken, refreshToken, profile, done) {

And also the scope passport.authenticate('facebook', { scope: ['email', 'public_profile'] })

Would appreciate your help. thanks!

About this issue

Most upvoted comments

Facebook is shit, developpers are getting crazy for standard shit like this. it’s my 10th install (5+ different scripting languages and libs to fb connect) and everytime i cry. hope it helps

here’s my working data :

passport.use(new FacebookStrategy({ clientID: ‘xxxxx’, clientSecret: ‘xxxxxxxx’, callbackURL: “http://localhost:3000/auth/facebook/callback”, profileFields: [‘id’, ‘displayName’, ‘email’, ‘birthday’, ‘friends’, ‘first_name’, ‘last_name’, ‘middle_name’, ‘gender’, ‘link’] }, function(accessToken, refreshToken, profile, cb) { User.findOrCreate({ facebookId: profile.id }, function (err, user) { return cb(err, user); }); } )); app.get(‘/auth/facebook’, passport.authenticate(‘facebook’, { authType: ‘rerequest’, scope: [‘user_friends’, ‘email’, ‘public_profile’], } )); app.get(‘/auth/facebook/callback’, passport.authenticate(‘facebook’, { failureRedirect: ‘/login’, }), function(req, res) { res.redirect(‘/’); } );

@VulcanRav Thanks for the tips but I already checked them. I’m using my own account. I only have an email address and no phone number. But the result contains just name and id . The email field is not present at all.

No email field here either. The only things I get back are name and id. That’s all. Even with profileFields and scope declared. Any ideas?

This is a pain in 2020

router.get('/auth/facebook', passport.authorize('facebook', {
    authType: 'rerequest', 
    scope : ['email', 'public_profile'] }));

and

passport.use(new FacebookStrategy({
    clientID: process.env.FACEBOOK_APP_ID,
    clientSecret: process.env.FACEBOOK_APP_SECRET,
    callbackURL: process.env.FACEBOOK_CALLBACK_URL,
    profileFields: ['id', 'email', 'displayName', 'photos']
  },
  function(facebookAccessToken, refreshToken, profile, done) {

email is empty 👎

Please check your Facebook app/page permission list for those still struggling to get email information. By default, public_profile permission is given. you have to add email to the permission list to make it work

Have the same issue, scope and postFields didn’t work, Will remove the shit FB login from the website, that’s waste of time. 😡

For anyone seeing this in the future, you have to do 2 things:

/**
 * @api {get} /v1/auth/facebook
 * @apiName FacebookOAuth
 * @apiGroup Auth
 */
router.get("/facebook", passport.authenticate("facebook", { scope: ["email"] }));

and

const facebookStrategyOptions: any = {
  clientID: FACEBOOK_CLIENT_ID,
  clientSecret: FACEBOOK_CLIENT_SECRET,
  callbackURL: FACEBOOK_REDIRECT_URI,
  profileFields: ["email"]
};

and it will (or may?) work.

@rafipiccolo solution worked. It seems like they need to update the api call from 2.4 to 2.9