Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emails are empty #91

Open
Nainabbas opened this issue Jan 15, 2020 · 6 comments
Open

Emails are empty #91

Nainabbas opened this issue Jan 15, 2020 · 6 comments

Comments

@Nainabbas
Copy link

Even though I have the access_token with email access and i have write the scope of email in passport it's not getting the email of the user.

@Nainabbas
Copy link
Author

Nainabbas commented Jan 15, 2020

`
passport.use(
"facebookToken",
new FacebookTokenStrategy(
{
clientID: process.env.FB_APP_ID,
clientSecret: process.env.FB_APP_SECRET,
passReqToCallback: true,
profileFields: ["id", "displayName", "name", "gender", "emails"]
},
async (req, accessToken, refreshToken, profile, done) => {
try {
//check if user exsists in database
//...
//if not make new user
//....
//genrate token
console.log(profile);
var token = await jwt.sign(profile, process.env.JWT_SECRET);
req.access_token = token;
return done(null, req.access_token);
} catch (err) {
done(err, false, err.message);
}
}
)
);

`

@Nainabbas
Copy link
Author

router.post(
"/login/facebook",
passport.authenticate("facebookToken", {
scope: ["email", "public_profile"],
session: false
}),
authController.loginFacebook
);

@ghaiklor
Copy link
Collaborator

Did you try use emails instead of email?

@Nainabbas
Copy link
Author

not worked

@Shyam-Chen
Copy link

Shyam-Chen commented Jan 6, 2021

Client Requests:

FB.login(
  function(response) {
    if (response.status === 'connected') {
      axios
        .get('http://0.0.0.0:3000/auth/facebook/token', {
          params: {
            access_token: response.authResponse.accessToken,
          },
        })
        .then(({ data }) => {
          console.log('data =', data);
        });
    } else {
      // The person is not logged into your webpage or we are unable to tell.
    }
  },
  { scope: 'email' },
);

Use in Vue:

<template>
  <FacebookLogin app-id="XXX" version="v9.0" @login="fbLogin" />
</template>

<script>
import FacebookLogin from 'vue-facebook-login-component';
import axios from 'axios';

export default {
  components: {
    FacebookLogin,
  },
  methods: {
    fbLogin({ authResponse }) {
      axios
        .get('http://0.0.0.0:3000/auth/facebook/token', {
          params: {
            access_token: authResponse.accessToken,
          },
        })
        .then(({ data }) => {
          console.log('data =', data);
        });
    },
  },
};
</script>

@MakakWasTaken
Copy link

I recently started using this framework as well and experienced the same issue as you are having with the email not being present. I was using a Facebook test user and got the access token through the Facebook API dashboard.

The first thing I noted with your code is that the router should use passport.authenticate("passport-facebook-token") instead. Like this:

router.post(
  "/login/facebook",
  passport.authenticate("passport-facebook-token", {
    scope: ["email", "public_profile"],
    session: false,
  }),
  authController.loginFacebook
);

I am not sure this fixes anything for you.

My next problem was that my test user did not have the email permission for some reason. You can check the permissions by sending a request to the following URL. (With your access token as your Authorization parameter):
https://graph.facebook.com/v10.0/me/permissions
Mine said something like:

[...]
        {
            "permission": "email",
            "status": "expired"
        }
[...]

What fixed it for me was using my own user instead. (I still have not figured out why this is happening to the test user).
You can get a personal access_token from: https://developers.facebook.com/tools/explorer/

Hope this helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants