Django social auth using facebook data

I managed to install django-social-auth, but I miss the moment when I can actually use the data obtained from facebook to create a username and, possibly, use a profile picture or 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 do not limit where in my code I can connect this data, so I do not have random usernames .

+4
source share
1 answer

django-social-auth implements a pipeline (this seems to be a new function that was not there when I tried it), which allows you to insert custom functions at certain stages of the authentication process. Here you can find documents and an example pipline function .

So you can 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 custom_create_user by default and creates a username according to 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) 
+13
source

Source: https://habr.com/ru/post/1397309/


All Articles