Updated access token view to return a JWT as an access token

The JWT includes the user email and username, along with details pulled from the original access token (e.g. scope, expiration).

ECOM-4221
This commit is contained in:
Clinton Blackburn
2016-04-19 18:10:39 -04:00
committed by Clinton Blackburn
parent 5adf6fec66
commit 6941fcd766
9 changed files with 233 additions and 28 deletions

View File

@@ -111,8 +111,10 @@ class CcxRestApiTest(CcxTestCase, APITestCase):
token_resp = self.client.post('/oauth2/access_token/', data=token_data)
self.assertEqual(token_resp.status_code, status.HTTP_200_OK)
token_resp_json = json.loads(token_resp.content)
self.assertIn('access_token', token_resp_json)
return 'Bearer {0}'.format(token_resp_json.get('access_token'))
return '{token_type} {token}'.format(
token_type=token_resp_json['token_type'],
token=token_resp_json['access_token']
)
def expect_error(self, http_code, error_code_str, resp_obj):
"""

View File

@@ -17,6 +17,7 @@ from rest_framework_oauth.authentication import OAuth2Authentication
from ccx_keys.locator import CCXLocator
from courseware import courses
from edx_rest_framework_extensions.authentication import JwtAuthentication
from instructor.enrollment import (
enroll_email,
get_email_params,
@@ -361,7 +362,7 @@ class CCXListView(GenericAPIView):
]
}
"""
authentication_classes = (OAuth2Authentication, SessionAuthentication,)
authentication_classes = (JwtAuthentication, OAuth2Authentication, SessionAuthentication,)
permission_classes = (IsAuthenticated, permissions.IsMasterCourseStaffInstructor)
serializer_class = CCXCourseSerializer
pagination_class = CCXAPIPagination
@@ -599,7 +600,7 @@ class CCXDetailView(GenericAPIView):
response is returned.
"""
authentication_classes = (OAuth2Authentication, SessionAuthentication,)
authentication_classes = (JwtAuthentication, OAuth2Authentication, SessionAuthentication,)
permission_classes = (IsAuthenticated, permissions.IsCourseStaffInstructor)
serializer_class = CCXCourseSerializer