mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-29 13:04:03 +03:00
Support basic authentication with custom user models that change username field
Support basic authentication with custom user models with a username field that is not named 'username'.
This commit is contained in:
parent
e33fed70d6
commit
bb002262ac
|
@ -4,6 +4,7 @@ Provides various authentication policies.
|
|||
from __future__ import unicode_literals
|
||||
import base64
|
||||
from django.contrib.auth import authenticate
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.middleware.csrf import CsrfViewMiddleware
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from rest_framework import exceptions, HTTP_HEADER_ENCODING
|
||||
|
@ -85,7 +86,11 @@ class BasicAuthentication(BaseAuthentication):
|
|||
"""
|
||||
Authenticate the userid and password against username and password.
|
||||
"""
|
||||
user = authenticate(username=userid, password=password)
|
||||
credentials = {
|
||||
get_user_model().USERNAME_FIELD: userid,
|
||||
'password': password
|
||||
}
|
||||
user = authenticate(**credentials)
|
||||
|
||||
if user is None:
|
||||
raise exceptions.AuthenticationFailed(_('Invalid username/password.'))
|
||||
|
|
Loading…
Reference in New Issue
Block a user