mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-24 00:04:16 +03:00
Merge remote-tracking branch 'reference/master'
This commit is contained in:
commit
c7a988eb38
|
@ -310,6 +310,13 @@ class OAuth2Authentication(BaseAuthentication):
|
||||||
|
|
||||||
auth = get_authorization_header(request).split()
|
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':
|
if auth and auth[0].lower() == b'bearer':
|
||||||
access_token = auth[1]
|
access_token = auth[1]
|
||||||
elif 'access_token' in request.POST:
|
elif 'access_token' in request.POST:
|
||||||
|
@ -319,13 +326,6 @@ class OAuth2Authentication(BaseAuthentication):
|
||||||
else:
|
else:
|
||||||
return None
|
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)
|
return self.authenticate_credentials(request, access_token)
|
||||||
|
|
||||||
def authenticate_credentials(self, request, access_token):
|
def authenticate_credentials(self, request, access_token):
|
||||||
|
|
|
@ -549,6 +549,15 @@ class OAuth2Tests(TestCase):
|
||||||
response = self.csrf_client.get('/oauth2-test/', HTTP_AUTHORIZATION=auth)
|
response = self.csrf_client.get('/oauth2-test/', HTTP_AUTHORIZATION=auth)
|
||||||
self.assertEqual(response.status_code, 401)
|
self.assertEqual(response.status_code, 401)
|
||||||
|
|
||||||
|
@unittest.skipUnless(oauth2_provider, 'django-oauth2-provider not installed')
|
||||||
|
def test_get_form_with_wrong_authorization_header_token_missing(self):
|
||||||
|
"""Ensure that a missing token lead to the correct HTTP error status code"""
|
||||||
|
auth = "Bearer"
|
||||||
|
response = self.csrf_client.get('/oauth2-test/', {}, HTTP_AUTHORIZATION=auth)
|
||||||
|
self.assertEqual(response.status_code, 401)
|
||||||
|
response = self.csrf_client.get('/oauth2-test/', HTTP_AUTHORIZATION=auth)
|
||||||
|
self.assertEqual(response.status_code, 401)
|
||||||
|
|
||||||
@unittest.skipUnless(oauth2_provider, 'django-oauth2-provider not installed')
|
@unittest.skipUnless(oauth2_provider, 'django-oauth2-provider not installed')
|
||||||
def test_get_form_passing_auth(self):
|
def test_get_form_passing_auth(self):
|
||||||
"""Ensure GETing form over OAuth with correct client credentials succeed"""
|
"""Ensure GETing form over OAuth with correct client credentials succeed"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user