mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-05 04:50:12 +03:00
Merge cb4150b4f9
into fd72a814f8
This commit is contained in:
commit
5d63b3fe72
|
@ -167,6 +167,16 @@ class TokenAuthentication(BaseAuthentication):
|
|||
"""
|
||||
|
||||
def authenticate(self, request):
|
||||
# Get the underlying HttpRequest object
|
||||
request = request._request
|
||||
user = getattr(request, 'user', None)
|
||||
|
||||
# If we have a logged-in user, skip checking and let the user pass
|
||||
if user and user.is_active:
|
||||
token = self.model.objects.get_or_create(user=user)[0]
|
||||
|
||||
return (user, token)
|
||||
|
||||
auth = get_authorization_header(request).split()
|
||||
|
||||
if not auth or auth[0].lower() != self.keyword.lower().encode():
|
||||
|
|
Loading…
Reference in New Issue
Block a user