mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-26 00:10:44 +03:00
Adding BasicAuthentication.extract_credentials()
This commit is contained in:
parent
1f9a8e10e5
commit
035bd25dcf
|
@ -56,6 +56,18 @@ class BasicAuthentication(BaseAuthentication):
|
|||
Returns a :obj:`User` if a correct username and password have been supplied
|
||||
using HTTP Basic authentication. Otherwise returns :const:`None`.
|
||||
"""
|
||||
uname, passwd = self.extract_credentials(request)
|
||||
if uname:
|
||||
user = authenticate(username=uname, password=passwd)
|
||||
if user is not None and user.is_active:
|
||||
return user
|
||||
return None
|
||||
|
||||
def extract_credentials(self, request):
|
||||
"""
|
||||
Extracts username, password from HTTP Auth Basic header if they have
|
||||
been set. Otherwise returns :const:`None`, :const:`None`.
|
||||
"""
|
||||
from django.utils.encoding import smart_unicode, DjangoUnicodeDecodeError
|
||||
|
||||
if 'HTTP_AUTHORIZATION' in request.META:
|
||||
|
@ -71,10 +83,9 @@ class BasicAuthentication(BaseAuthentication):
|
|||
except DjangoUnicodeDecodeError:
|
||||
return None
|
||||
|
||||
user = authenticate(username=uname, password=passwd)
|
||||
if user is not None and user.is_active:
|
||||
return user
|
||||
return None
|
||||
return uname, passwd
|
||||
|
||||
return None, None
|
||||
|
||||
|
||||
class UserLoggedInAuthentication(BaseAuthentication):
|
||||
|
|
Loading…
Reference in New Issue
Block a user