Support basic authentication with custom user models that change username field by Ernest0x · Pull Request #2952 · encode/django-rest-framework (original) (raw)

Using the username argument appears to work fine with Django's ModelBackend auth backend, regardless of the name of the username field. Looks like it only uses UserModel.USERNAME_FIELD as a back up. https://docs.djangoproject.com/en/1.8/_modules/django/contrib/auth/backends/

Looks okay, but I might need a little more persuading of the necessity for the change.

It works fine with Django's ModelBackend but it may not work with other backends, so better be safer than sorry. Particularly, it does not work with django-python3-ldap.

According to Django's documentation, an authentication backend is required to implement authenticate(**credentials), which does not dictate the parameter names. That said, using USERNAME_FIELD instead of a hardcoded 'username' is a safer approach imho.