Reputation: 109
Hello I'd like to allow users to login/register through facebook. Authentication works but backend creates User instance with the combination of first and last name (from Facebook) as a username and no email. Google oauth2 backend works just fine.
Here are my settings:
FACEBOOK_APP_ID = 'appid'
FACEBOOK_API_SECRET = 'apisecret'
FACEBOOK_EXTENDED_PERMISSIONS = ['email']
SOCIAL_AUTH_CREATE_USERS = True
SOCIAL_AUTH_FORCE_RANDOM_USERNAME = False
SOCIAL_AUTH_DEFAULT_USERNAME = 'socialauth_user'
SOCIAL_AUTH_COMPLETE_URL_NAME = 'socialauth_complete'
SOCIAL_AUTH_ASSOCIATE_URL_NAME = 'socialauth_associate_complete'
LOGIN_ERROR_URL = '/login/error/'
LOGIN_REDIRECT_URL = '/'
SOCIAL_AUTH_USER_MODEL = 'users.User'
SESSION_SERIALIZER = django.contrib.sessions.serializers.PickleSerializer'
My app should create users with email filled with data(email) from facebook. I can't overcome this. Can anyone help?
Upvotes: 0
Views: 317
Reputation: 312
In python-social-auth (which replaces django-social-auth) you have to set these two to obtain email from FB:
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']
SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = {
'locale': 'pl_PL',
'fields': 'id, name, email',
}
SOCIAL_AUTH_FACEBOOK_SCOPE
is equivalent of FACEBOOK_EXTENDED_PERMISSIONS
, and I guess SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS
is equivalent of FACEBOOK_PROFILE_EXTRA_PARAMS
. So I would try:
FACEBOOK_EXTENDED_PERMISSIONS = ['email']
FACEBOOK_PROFILE_EXTRA_PARAMS = {
'locale': 'pl_PL',
'fields': 'id, name, email',
}
Upvotes: 1