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

风格不统一 提交于 2019-12-03 00:12:06

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'],
    },
Nikola

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.

Amit Fegade

You need to specify the scope: "email". Refer the below code.

Facebook authentication route:

// auth facebook
router.get("/auth/facebook", passport.authenticate("facebook", {
  scope: "email"
}));

and while configuring the FacebookStrategy, you need to also specify the profileFields.

passport.use(new FacebookStrategy({
  callbackURL: "http://localhost:5000/auth/facebook/redirect",
  clientID: keys.facebook.clientID,
  clientSecret: keys.facebook.clientSecret,
  profileFields: ['id', 'displayName', 'photos', 'email', 'gender', 'name']
}, (accessToken, refreshToken, profile, done) => {
   // logic 
}))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!