I want to add a function at the end of the auth pipeline, the function is meant to check if there is a "Profiles" table for that user, if there isn't it will create a table. The Profiles model is a table where I store some extra information about the user:
class Profiles(models.Model):user = models.OneToOneField(User, unique=True, null=True)description = models.CharField(max_length=250, blank=True, null=True)points = models.SmallIntegerField(default=0)posts_number = models.SmallIntegerField(default=0)
Each user must have a Profiles table. So, I added a function at the end of the pipeline:
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','social.pipeline.user.create_user','social.pipeline.social_auth.associate_user','social.pipeline.social_auth.load_extra_data','social.pipeline.user.user_details','app.utils.create_profile' #Custom pipeline
)#utils.py
def create_profile(strategy, details, response, user, *args, **kwargs):username = kwargs['details']['username']user_object = User.objects.get(username=username)if Profiles.ojects.filter(user=user_object).exists():passelse:new_profile = Profiles(user=user_object)new_profile.save()return kwargs
I get the error:
KeyError at /complete/facebook/'details'...utils.py in create_profileusername = kwargs['details']['username']
I'm new to python social auth, and it looks that I'm missing something obvious. Any help will be appreciated.