javascript - Passport-Facebook authentication is not providing email for all Facebook accounts -
i using passport-facebook authentication.
passport.use(new facebookstrategy({ clientid: 'client_id', clientsecret: 'client_secret', callbackurl: "http://www.example.com/auth/facebook/callback" }, function (accesstoken, refreshtoken, profile, done) { process.nexttick(function () { console.log(profile) }); } ));
for of facebook accounts don't email_id , tried using scope variable such below, still unable email_id.
profileurl : " " , profilefields : ['','']
make sure these 2 things in code:
passport.use(new facebookstrategy({ clientid: 'client_id', clientsecret: 'client_secret', callbackurl: "http://www.example.com/auth/facebook/callback" passreqtocallback : true, profilefields: ['id', 'emails', 'name'] //this },
and this:
app.get('/connect/facebook', passport.authorize('facebook', { scope : ['email'] }));
this gives access following:
- profile.id
- profile.name.givenname
- profile.name.familyname
- profile.emails
the last 1 being array, use profile.emails[0].value
first email address of user.
as shamim reza
pointed out, might want check if profile.emails !== undefined
because property exists if user has @ least 1 verified email address.
Comments
Post a Comment