aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/authentication.py
diff options
context:
space:
mode:
authorTom Christie2014-07-26 20:57:28 +0100
committerTom Christie2014-07-26 20:57:28 +0100
commit02187eb2edf34a992bc56da797caded085b1e09a (patch)
tree1c34f45e49da416bd694809b1f6e9c1e708fb047 /rest_framework/authentication.py
parent299a8347e8ef448eefc611eebfe80d7e142ceaa1 (diff)
parente3aff6a5678d48a2e328c9bb44b7c3de81caffd5 (diff)
downloaddjango-rest-framework-02187eb2edf34a992bc56da797caded085b1e09a.tar.bz2
Merge pull request #1705 from opbeat/master
Sending "Bearer" and "Bearer " resulted in a 500.
Diffstat (limited to 'rest_framework/authentication.py')
-rw-r--r--rest_framework/authentication.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/rest_framework/authentication.py b/rest_framework/authentication.py
index da9ca510..887ef5d7 100644
--- a/rest_framework/authentication.py
+++ b/rest_framework/authentication.py
@@ -310,6 +310,13 @@ class OAuth2Authentication(BaseAuthentication):
auth = get_authorization_header(request).split()
+ if len(auth) == 1:
+ msg = 'Invalid bearer header. No credentials provided.'
+ raise exceptions.AuthenticationFailed(msg)
+ elif len(auth) > 2:
+ msg = 'Invalid bearer header. Token string should not contain spaces.'
+ raise exceptions.AuthenticationFailed(msg)
+
if auth and auth[0].lower() == b'bearer':
access_token = auth[1]
elif 'access_token' in request.POST:
@@ -319,13 +326,6 @@ class OAuth2Authentication(BaseAuthentication):
else:
return None
- if len(auth) == 1:
- msg = 'Invalid bearer header. No credentials provided.'
- raise exceptions.AuthenticationFailed(msg)
- elif len(auth) > 2:
- msg = 'Invalid bearer header. Token string should not contain spaces.'
- raise exceptions.AuthenticationFailed(msg)
-
return self.authenticate_credentials(request, access_token)
def authenticate_credentials(self, request, access_token):