diff --git a/lms/djangoapps/oauth2_handler/handlers.py b/lms/djangoapps/oauth2_handler/handlers.py index c898008e1d..122ccd41ff 100644 --- a/lms/djangoapps/oauth2_handler/handlers.py +++ b/lms/djangoapps/oauth2_handler/handlers.py @@ -54,7 +54,7 @@ class ProfileHandler(object): def scope_profile(self, _data): """ Add specialized claims. """ - return ['name', 'locale'] + return ['name', 'locale', 'user_tracking_id'] def claim_name(self, data): """ User displayable full name. """ @@ -77,6 +77,10 @@ class ProfileHandler(object): return language + def claim_user_tracking_id(self, data): + """ User tracking ID. """ + return data['user'].id + class CourseAccessHandler(object): """ diff --git a/lms/djangoapps/oauth2_handler/tests.py b/lms/djangoapps/oauth2_handler/tests.py index 6c304733c8..96a7b3d4c8 100644 --- a/lms/djangoapps/oauth2_handler/tests.py +++ b/lms/djangoapps/oauth2_handler/tests.py @@ -73,6 +73,11 @@ class IDTokenTest(BaseTestMixin, IDTokenTestCase): locale = claims['locale'] self.assertEqual(language, locale) + def test_user_tracking_id_claim(self): + scopes, claims = self.get_id_token_values('openid profile') + self.assertIn('profile', scopes) + self.assertEqual(claims['user_tracking_id'], self.user.id) + def test_no_special_course_access(self): with check_mongo_calls(0): scopes, claims = self.get_id_token_values('openid course_instructor course_staff') @@ -232,3 +237,8 @@ class UserInfoTest(BaseTestMixin, UserInfoTestCase): self.user.save() claims = self.get_with_scope('permissions') self.assertTrue(claims['administrator']) + + def test_profile_scope(self): + claims = self.get_with_scope('profile') + self.assertEqual(claims['name'], UserProfile.objects.get(user=self.user).name) + self.assertEqual(claims['user_tracking_id'], self.user.id)