python social auth and django, email empty with Facebook api 2.4
Asked Answered
C

1

5

I am using python social auth with my django project for providing Facebook login functionality. I can see the email being supplied from facebook in the popup. But it is coming as empty in my partial pipeline. The same code was working fine with my other Facebook app with the exact same settings apart from api version (previously it was 2.3 and now its 2.4). There is no option to change the Facebook api version to 2.3 also. My python-social-auth version is 0.2.12 Following are the relevant data from my settings file

SOCIAL_AUTH_FACEBOOK_SCOPE = ['email',]
FACEBOOK_EXTENDED_PERMISSIONS = ['email',]
SOCIAL_AUTH_USERNAME_IS_FULL_EMAIL = True
SOCIAL_AUTH_PROTECTED_USER_FIELDS = ['email',]
SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/'
SOCIAL_AUTH_LOGIN_ERROR_URL = '/'

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',
    'home.pipeline.require_email',
    'social.pipeline.social_auth.associate_by_email',  # <--- enable this one
    'social.pipeline.user.create_user',
    'social.pipeline.social_auth.associate_user',
    'social.pipeline.social_auth.load_extra_data',
    'social.pipeline.user.user_details',
    'home.pipeline.send_welcome_mail',
)

SOCIAL_AUTH_FACEBOOK_KEY = os.environ['SOCIAL_AUTH_FACEBOOK_KEY']
SOCIAL_AUTH_FACEBOOK_SECRET = os.environ['SOCIAL_AUTH_FACEBOOK_SECRET']

This is my custom partial pipeline function

@partial
def require_email(strategy, backend, uid, details, user=None, *args, **kwargs):
    print details
    #some stuff......

This function prints the empty email id as shown below

{'username': u'Anurag Jain', 'fullname': u'Anurag Jain', 'last_name': u'Jain', 'email': '', 'first_name': u'Anurag'}

Can anybody help me figure out the problem with this.

Cobaltic answered 28/7, 2015 at 8:59 Comment(0)
C
9

It turns out that there were some changes made in the Facebook api v2.4 which resulted in email being empty. There is already an issue open for this https://github.com/omab/python-social-auth/issues/675

The solution is to add the following setting to the django config file

SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = {
    'fields': 'id,name,email', # needed starting from protocol v2.4
}
Cobaltic answered 28/7, 2015 at 15:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.