aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/authentication.py
diff options
context:
space:
mode:
authorDmitry Mukhin2014-08-20 20:04:48 +0400
committerDmitry Mukhin2014-08-20 20:04:48 +0400
commit3b07d0c9978335e183f369480618b48ff1e1b1ab (patch)
tree041027c50d2965da1be7f93b1a6360e07ad976f9 /rest_framework/authentication.py
parentc3891b6e00daa7a92cca1c88599e046f72926bb4 (diff)
parent59b47eac14778767a17e56bd8adc0610417f2878 (diff)
downloaddjango-rest-framework-3b07d0c9978335e183f369480618b48ff1e1b1ab.tar.bz2
Merge branch 'master' into set-retry-after
Conflicts: tests/test_throttling.py
Diffstat (limited to 'rest_framework/authentication.py')
-rw-r--r--rest_framework/authentication.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/rest_framework/authentication.py b/rest_framework/authentication.py
index da9ca510..5721a869 100644
--- a/rest_framework/authentication.py
+++ b/rest_framework/authentication.py
@@ -6,9 +6,9 @@ import base64
from django.contrib.auth import authenticate
from django.core.exceptions import ImproperlyConfigured
+from django.middleware.csrf import CsrfViewMiddleware
from django.conf import settings
from rest_framework import exceptions, HTTP_HEADER_ENCODING
-from rest_framework.compat import CsrfViewMiddleware
from rest_framework.compat import oauth, oauth_provider, oauth_provider_store
from rest_framework.compat import oauth2_provider, provider_now, check_nonce
from rest_framework.authtoken.models import Token
@@ -21,7 +21,7 @@ def get_authorization_header(request):
Hide some test client ickyness where the header can be unicode.
"""
auth = request.META.get('HTTP_AUTHORIZATION', b'')
- if type(auth) == type(''):
+ if isinstance(auth, type('')):
# Work around django test client oddness
auth = auth.encode(HTTP_HEADER_ENCODING)
return auth
@@ -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):