Search code examples
expresspassport-facebook

Passport does not send scopes


I do pass email as scope as seen here:

router.get(keys.facebookCallbackURL, passport.authenticate('facebook', {
    scope: ['public_profile', 'email'], 
    failureRedirect: '/', 
    session: false }),
    (req, res) => {
        //...
    }
);

Generated url is:

https://www.facebook.com/v3.2/dialog/oauth?response_type=code&redirect_uri=https%3A%2F%2Flocalhost%3A5000%2Fauth%2Ffacebook%2Fcallback&client_id=123977854776367

which does not ask user to grant email, but when I append &scope=email%2Cpublic_profile to url manually it does.

Like this:

https://www.facebook.com/v3.2/dialog/oauth?response_type=code&redirect_uri=https%3A%2F%2Flocalhost%3A5000%2Fauth%2Ffacebook%2Fcallback&client_id=123977854776367&scope=email%2Cpublic_profile

Why scopes are not appended to url?


Solution

  • I was adding scopes to the wrong route.

    router.get(
      "/auth/google",
      passport.authenticate("google", {
        scope: ["profile", "email"]
      })
    );