Fixes #32 - Add `token_type` to access token response to conform to section 4.2.2 of the OAuth 2.0 specification.
This commit is contained in:
parent
a6bbb29916
commit
d53a9fbcb1
|
@ -11,6 +11,8 @@ CLIENT_TYPES = (
|
|||
|
||||
RESPONSE_TYPE_CHOICES = getattr(settings, 'OAUTH_RESPONSE_TYPE_CHOICES', ("code", "token"))
|
||||
|
||||
TOKEN_TYPE = 'Bearer'
|
||||
|
||||
READ = 1 << 1
|
||||
WRITE = 1 << 2
|
||||
READ_WRITE = READ | WRITE
|
||||
|
|
|
@ -234,6 +234,8 @@ class AccessTokenTest(BaseOAuth2TestCase):
|
|||
self.assertEqual('invalid_grant', json.loads(response.content)['error'])
|
||||
|
||||
def _login_authorize_get_token(self):
|
||||
required_props = ['access_token', 'token_type']
|
||||
|
||||
self.login()
|
||||
self._login_and_authorize()
|
||||
|
||||
|
@ -249,7 +251,13 @@ class AccessTokenTest(BaseOAuth2TestCase):
|
|||
|
||||
self.assertEqual(200, response.status_code, response.content)
|
||||
|
||||
return json.loads(response.content)
|
||||
token = json.loads(response.content)
|
||||
|
||||
for prop in required_props:
|
||||
self.assertIn(prop, token, "Access token response missing "
|
||||
"required property: %s" % prop)
|
||||
|
||||
return token
|
||||
|
||||
def test_fetching_access_token_with_valid_grant(self):
|
||||
self._login_authorize_get_token()
|
||||
|
@ -414,6 +422,10 @@ class AccessTokenTest(BaseOAuth2TestCase):
|
|||
self.assertEqual(400, response.status_code, response.content)
|
||||
self.assertEqual('invalid_grant', json.loads(response.content)['error'])
|
||||
|
||||
def test_access_token_response_valid_token_type(self):
|
||||
token = self._login_authorize_get_token()
|
||||
self.assertEqual(token['token_type'], constants.TOKEN_TYPE, token)
|
||||
|
||||
|
||||
class AuthBackendTest(BaseOAuth2TestCase):
|
||||
fixtures = ['test_oauth2']
|
||||
|
|
|
@ -451,6 +451,7 @@ class AccessToken(OAuthView, Mixin):
|
|||
|
||||
response_data = {
|
||||
'access_token': access_token.token,
|
||||
'token_type': constants.TOKEN_TYPE,
|
||||
'expires_in': access_token.get_expire_delta(),
|
||||
'scope': ' '.join(scope.names(access_token.scope)),
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue