I managed to install django-social-auth, but I am missing the moment where I can actually use the data obtained from facebook in order to create the username and maybe use the profile image or the about field...
I know that in the settings for django-social-auth I can set SOCIAL_AUTH_DEFAULT_USERNAME = 'new_social_auth_user' and FACEBOOK_EXTENDED_PERMISSIONS = [...] but I don't undestrand where in my code I can plug in this data, so not to have random usernames.
django-social-auth
implements a pipeline (this seems to be a new feature as it wasn't there when I was trying it out) that allows you to insert custom functions at certain steps in the process of authenticating. Check out the docs here, and an example pipline function here.
So you could write a function:
SOCIAL_AUTH_PIPELINE = (
'social_auth.backends.pipeline.social.social_auth_user',
'social_auth.backends.pipeline.associate.associate_by_email',
'social_auth.backends.pipeline.user.get_username',
'app.pipeline.custom_create_user',
'social_auth.backends.pipeline.social.associate_user',
'social_auth.backends.pipeline.social.load_extra_data',
'social_auth.backends.pipeline.user.update_user_details'
)
where your custom_create_user
function wraps the default create_user
and create the username according o your own needs:
from social_auth.backends.pipeline.user import create_user
def custom_create_user(request, *args, **kwargs):
user = *kwargs.get('user', None)
# Do something with username
return create_user(request, args, kwargs)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With