Issues with username field in Python-social-auth
Asked Answered
W

2

6

I am using Python socia auth for face-book. I have modified default Django behavior of User Model and removed username field .

I have added this in custom user model : USERNAME_FIELD = 'email'

BUt I am getting this error when trying to login

TypeError at /complete/facebook/
'username' is an invalid keyword argument for this function

I know when it is trying to create user it doesn't find username field and this throwing this error.

I have defined below settings but still my issue remains as it is :

SOCIAL_AUTH_USER_MODEL = 'accounts.User'
SOCIAL_AUTH_USERNAME_IS_FULL_EMAIL = True

Any solution for this ?

Whereto answered 2/4, 2015 at 13:5 Comment(1)
Did you find any solution for this problem? I am facing the exact same issue.Parmer
C
6

I know it's few months since the question was posted, but I hit the same problem and found the solution.

This problem can be solved using pipeline. The default pipeline does this:

def create_user(strategy, details, user=None, *args, **kwargs):
    if user:
        return {'is_new': False}

    fields = dict((name, kwargs.get(name) or details.get(name))
                  for name in strategy.setting('USER_FIELDS',
                                               USER_FIELDS))
    if not fields:
        return

    return {
        'is_new': True,
        'user': strategy.create_user(**fields)
    }

Override USER_FIELDS in your settings end leave only email. Alternatively you can create completely new create_user method.

Coca answered 16/8, 2015 at 9:18 Comment(0)
T
1

i have same issue and solved problem by adding user argument in create user field .. None: Argument 'username' is needed for social-auth. It is not actually used.

    class UserManager(BaseUserManager):
def create_user(self, email,username=None, full_name=None, password='&btCqv"}@,4TWd6A'):
    if not email:
        raise ValueError("Users must have an email address")
    if not password:
        raise ValueError("Users must have a password")
    user = self.model(
        email=self.normalize_email(email),
    )
    user.set_password(password)  # change user password
    user.staff = is_staff
    user.admin = is_admin
    user.is_active = is_active
    user.save(using=self._db)
    return user

if still problem persist refer: https://github.com/python-social-auth/social-app-django/issues/15#issuecomment-276118574

Thermion answered 23/4, 2018 at 11:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.