Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Authentication backend does not work with AbstractBaseUser custom user models #440

Open
smedisetti opened this issue Jan 14, 2021 · 1 comment

Comments

@smedisetti
Copy link

My django application contains a custom user model where email replaces the username authentication. Therefore, username removed in the User. As a result, it is not feasible to use the django_microsoft_auth package. Kindly help me out.

  • adding username might not be a good option for my application.
  • an example user model implementation is attached below
from django.db import models
from django.contrib.auth.models import AbstractBaseUser
from django.contrib.auth.models import PermissionsMixin
from django.utils.translation import gettext_lazy as _
from django.utils import timezone

from .managers import CustomUserManager


class CustomUser(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(_('email address'), unique=True)
    is_staff = models.BooleanField(default=False)
    is_active = models.BooleanField(default=True)
    date_joined = models.DateTimeField(default=timezone.now)

   USERNAME_FIELD = 'email'
   REQUIRED_FIELDS = []

  objects = CustomUserManager()

  def __str__(self):
      return 'self.email'
@AngellusMortis
Copy link
Owner

Username is hardcoded for user creation at the moment, so the package requires an AbstractUser, not an AbstractBaseUser. It is only used for user creation though, nothing afterwards so it should be easy to remove the requirement. It was not a requirement in my original creation of the package and one else as added it.

If you would like to make a PR for improvement to allow the backend to work better with user models created with AbstractBaseUser, feel free to make a PR.

@AngellusMortis AngellusMortis changed the title How feasible to use django_microsoft_auth for custom user model Authentication backend does not work with AbstractBaseUser custom user models Jan 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants