Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 567
Anurag Avatar asked Jul 28 '15 08:07

Anurag


1 Answers

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
}
like image 104
Anurag Avatar answered Nov 15 '22 03:11

Anurag