omab / python-social-auth

Social auth made simple
http://psa.matiasaguirre.net
BSD 3-Clause "New" or "Revised" License
2.83k stars 1.09k forks source link

Email is empty in login with Facebook #889

Closed mapeveri closed 8 years ago

mapeveri commented 8 years ago

When login with Facebook, the email is always empty:

This is my 'details' response:

{'fullname': 'name', 'first_name': 'first_name', 'username': 'username', 'email': '', 'last_name': 'last_name'}

The graph say 'granted':

image

My settings.py:

AUTHENTICATION_BACKENDS = ( 'social.backends.facebook.FacebookAppOAuth2', 'social.backends.facebook.FacebookOAuth2', 'social.backends.google.GoogleOpenId', 'social.backends.google.GoogleOAuth2', 'social.backends.google.GoogleOAuth', 'django.contrib.auth.backends.ModelBackend', )

SOCIAL_AUTH_URL_NAMESPACE = 'social'

SOCIAL_AUTH_LOGIN_REDIRECT_URL = "/"

SOCIAL_AUTH_LOGIN_URL = "/"

SOCIAL_AUTH_EMAIL_VALIDATION_FUNCTION = 'apps.main.mail.send_validation' SOCIAL_AUTH_EMAIL_VALIDATION_URL = '/email_sent/' SOCIAL_AUTH_FORCE_EMAIL_VALIDATION = True

SOCIAL_AUTH_PROTECTED_USER_FIELDS = ['email']

SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']

SOCIAL_AUTH_PIPELINE = ( 'social.pipeline.social_auth.social_details', 'social.pipeline.social_auth.social_uid', 'social.pipeline.social_auth.auth_allowed', 'social.pipeline.social_auth.social_user', 'social.pipeline.user.get_username', 'apps.main.pipelines.require_email', 'apps.main.pipelines.custom_mail_validation', 'social.pipeline.social_auth.associate_by_email',
'social.pipeline.user.create_user', 'social.pipeline.social_auth.associate_user', 'social.pipeline.social_auth.load_extra_data', 'social.pipeline.user.user_details', 'apps.main.pipelines.login' )

Any idea?

Thanks!

luis8 commented 8 years ago

@mapeveri I'm also facing this problem, did you find a solution?

luis8 commented 8 years ago

okay, i just find the solution. You need to add this to your settings file

SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = { 'fields': 'id,name,email', }

I didn't see this in the docs, so i think they need an update on this matter

mapeveri commented 8 years ago

@luis8 thanks, It works perfect.

One question:

This line:

SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']

What is the difference with the other line?

Thanks!

luis8 commented 8 years ago

@mapeveri the first one is for the email permissions in facebook, without it the facebook dialog wont ask for access to the email permission, but it seems like it is a little redundant IMO.

mapeveri commented 8 years ago

@luis8 perfect.

Thanks!