mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 19:40:13 +03:00
added in GET to token auth
This commit is contained in:
parent
e8c6cd5622
commit
42a2a5ef87
|
@ -150,19 +150,20 @@ class TokenAuthentication(BaseAuthentication):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def authenticate(self, request):
|
def authenticate(self, request):
|
||||||
auth = get_authorization_header(request).split()
|
parts = get_authorization_header(request).split()
|
||||||
|
if parts:
|
||||||
if not auth or auth[0].lower() != b'token':
|
if len(parts) == 1:
|
||||||
|
msg = 'Invalid token header. No credentials provided.'
|
||||||
|
raise exceptions.AuthenticationFailed(msg)
|
||||||
|
elif len(parts) > 2:
|
||||||
|
msg = 'Invalid token header. Token string should not contain spaces.'
|
||||||
|
raise exceptions.AuthenticationFailed(msg)
|
||||||
|
token = parts[1]
|
||||||
|
else:
|
||||||
|
token = request.GET.get('token', '')
|
||||||
|
if not token:
|
||||||
return None
|
return None
|
||||||
|
return self.authenticate_credentials(token)
|
||||||
if len(auth) == 1:
|
|
||||||
msg = 'Invalid token header. No credentials provided.'
|
|
||||||
raise exceptions.AuthenticationFailed(msg)
|
|
||||||
elif len(auth) > 2:
|
|
||||||
msg = 'Invalid token header. Token string should not contain spaces.'
|
|
||||||
raise exceptions.AuthenticationFailed(msg)
|
|
||||||
|
|
||||||
return self.authenticate_credentials(auth[1])
|
|
||||||
|
|
||||||
def authenticate_credentials(self, key):
|
def authenticate_credentials(self, key):
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user