Skip to content

Persona auth failing to authenticate when using a custom user model [Django] #253

@beaumartinez

Description

@beaumartinez

I've got a custom user model like so—

class User(AbstractBaseUser):
    email = models.EmailField(unique=True)

    USERNAME_FIELD = 'email'

I've added the appropriate social-auth settings—

AUTHENTICATION_BACKENDS = (
    'social.backends.persona.PersonaAuth',
)

AUTH_USER_MODEL = 'accounts.User'
SOCIAL_AUTH_USER_MODEL = 'accounts.User'

When trying to log in, a user with the email beau@<domain> gets created, however the email in the database is set to something like beau1234567890. That user doesn't authenticate (ie, request.user is still AnonymousUser).

If I nuke the AUTH_USER_MODEL and SOCIAL_AUTH_USER_MODEL, I can log in fine.

I'm speculating the issue is because the user model has a field called email, but it's also the USERNAME_FIELD. Hence, trying to create a user, social-auth creates a unique username, and overrides the email with that, assuming we'd have separate email and username fields—which is the case when using the default, django.contrib.auth.models.User model.

Any ideas on how to fix this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions