Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passport-Facebook not providing email even if it is in scope

In my application i register the facebook-strategie as follows: But the returned profile does not contain the email-field....

passport.use(new FacebookStrategy({
        clientID: config.facebook.clientID,
        clientSecret: config.facebook.clientSecret,
        callbackURL: config.facebook.callbackURL,
        passReqToCallback: true
    },
    function(req, accessToken, refreshToken, profile, done) {
        // No email in the following colsole.log
        console.log(JSON.stringify(profile));
    }));

The get is as follows:

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

(So i am using scope as said here: Passport-facebook doesn't get email)

On the FB-Login Page iam even asked for the email and i do provide it: enter image description here

Any help is very appriciated!

like image 677
Rentrop Avatar asked Jul 07 '15 20:07

Rentrop


2 Answers

From Facebook graph APIv2.4, we need to explicitly specify fields to get.

Introducing Graph API v2.4

So, we can write like:

  passport.use(new FacebookStrategy({
      clientID: config.facebook.clientID,
      clientSecret: config.facebook.clientSecret,
      callbackURL: config.facebook.callbackURL,
      profileFields: ['id', 'email', 'gender', 'link', 'locale', 'name', 'timezone', 'updated_time', 'verified'],
    },
like image 115
Tsuneo Yoshioka Avatar answered Sep 27 '22 23:09

Tsuneo Yoshioka


You do have the callback part of the code, right?:

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

And, yes, indeed, this should be done with the scope:['email'], as per instructions from your link and this one here also.

like image 45
Nikola Avatar answered Sep 27 '22 23:09

Nikola