Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issues with username field in Python-social-auth

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 ?

like image 592
n.imp Avatar asked Apr 02 '15 13:04

n.imp


2 Answers

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.

like image 100
ezaquarii Avatar answered Nov 16 '22 21:11

ezaquarii


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

like image 44
Adarsh Patel Avatar answered Nov 16 '22 21:11

Adarsh Patel