mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-26 16:30:41 +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
|
Returns a :obj:`User` if a correct username and password have been supplied
|
||||||
using HTTP Basic authentication. Otherwise returns :const:`None`.
|
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
|
from django.utils.encoding import smart_unicode, DjangoUnicodeDecodeError
|
||||||
|
|
||||||
if 'HTTP_AUTHORIZATION' in request.META:
|
if 'HTTP_AUTHORIZATION' in request.META:
|
||||||
|
@ -71,10 +83,9 @@ class BasicAuthentication(BaseAuthentication):
|
||||||
except DjangoUnicodeDecodeError:
|
except DjangoUnicodeDecodeError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
user = authenticate(username=uname, password=passwd)
|
return uname, passwd
|
||||||
if user is not None and user.is_active:
|
|
||||||
return user
|
return None, None
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
class UserLoggedInAuthentication(BaseAuthentication):
|
class UserLoggedInAuthentication(BaseAuthentication):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user