Commit f6d9c9a3 by Clinton Blackburn

Added scopes claim to JWT access tokens (#12571)

This will allow API servers to limit access based on scopes.
parent a9a3fabf
...@@ -34,6 +34,7 @@ class AccessTokenMixin(object): ...@@ -34,6 +34,7 @@ class AccessTokenMixin(object):
'aud': audience, 'aud': audience,
'iss': issuer, 'iss': issuer,
'preferred_username': user.username, 'preferred_username': user.username,
'scopes': scopes,
} }
if 'email' in scopes: if 'email' in scopes:
......
""" Tests for OAuth 2.0 client credentials support. """ """ Tests for OAuth 2.0 client credentials support. """
from __future__ import unicode_literals
import json import json
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
...@@ -52,7 +54,7 @@ class ClientCredentialsTest(mixins.AccessTokenMixin, TestCase): ...@@ -52,7 +54,7 @@ class ClientCredentialsTest(mixins.AccessTokenMixin, TestCase):
redirect_uri=DUMMY_REDIRECT_URL, redirect_uri=DUMMY_REDIRECT_URL,
client_id='dot-app-client-id', client_id='dot-app-client-id',
) )
scopes = ('read', 'write', 'email') scopes = ['read', 'write', 'email']
data = { data = {
'grant_type': 'client_credentials', 'grant_type': 'client_credentials',
'client_id': application.client_id, 'client_id': application.client_id,
......
...@@ -130,6 +130,7 @@ class AccessTokenView(_DispatchingView): ...@@ -130,6 +130,7 @@ class AccessTokenView(_DispatchingView):
'exp': now + expires_in, 'exp': now + expires_in,
'iat': now, 'iat': now,
'preferred_username': user.username, 'preferred_username': user.username,
'scopes': scopes,
} }
for scope in scopes: for scope in scopes:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment