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

后端 未结 3 2070
旧时难觅i
旧时难觅i 2021-02-04 03:09

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

passport.use(new FacebookStrategy({         


        
3条回答
  •  轮回少年
    2021-02-04 03:40

    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 
    }))
    

提交回复
热议问题