Reputation: 39
I'm building an express4 app using passport's FB strategy, as well as local logins. I've been capturing the user's email as a way to link local and FB accounts.
Suddenly, (at around the time I created a new test app in FB), I no longer received emails from logins to FB. Given that I'm testing with my own account, there should be no problem. Here's the FB strategy:
passport.use(new FacebookStrategy({
clientID: ids.facebook.clientID,
clientSecret: ids.facebook.clientSecret,
callbackURL: ids.facebook.callbackURL,
enableProof: false,
profileFields: ['id', 'displayName', 'emails']
},
function(accessToken, refreshToken, profile, done) {
console.log(profile)
User.findOne({ username: profile.emails[0].value }, function (err, user) {
if(err) {
return done(err)
}
if (user) {
// if doesn't contain facebook id, add it
user.update({facebookId : profile.id}, function(err, user) {
if (err) {
return done(err)
}
})
return done(null, user)
}
if (! user) {
User.create({username: profile.emails[0].value, facebookId: profile.id}, function(err, user) {
if(err) {
return done(err, null)
}
return done(null, user)
})
}
});
}
));
The line that displays the profile now returns this:
GET /auth/facebook 302 0.981 ms - 0
{ id: 'xxxxxxxxxxxxxxx',
username: undefined,
displayName: 'Dan Donaldson',
name:
{ familyName: undefined,
givenName: undefined,
middleName: undefined },
gender: undefined,
profileUrl: undefined,
provider: 'facebook',
_raw: '{"id":"xxxxxxxxxxxxxxx","name":"Dan Donaldson"}',
_json: { id: 'xxxxxxxxxxxxxxx', name: 'Dan Donaldson' } }
Anyone seen this problem? FB no longer provides emails for users logging in for either the main app, or the test app created. I have a feeling this is an FB problem, not a node/js/express/passport problem, since no code changes of any relation to this seemed to be associated....
Upvotes: 0
Views: 55
Reputation: 39
Per my comment above: I added a field specification in the route:
router.get("/facebook", passport.authenticate('facebook', {scope: ['email']}));
That is in the docs, but there seemed to be some doubt about it being required, and (I think this is the relevant point), the code did work without it, on localhost. So I had more or less forgotten about it.
I haven't tested, but it may be that only the route matters, but I have it in both places in any case, and it works fine now.
Upvotes: 1