diff --git a/lms/djangoapps/oauth2_handler/handlers.py b/lms/djangoapps/oauth2_handler/handlers.py index 32a38d29bc..5cece9b9e4 100644 --- a/lms/djangoapps/oauth2_handler/handlers.py +++ b/lms/djangoapps/oauth2_handler/handlers.py @@ -3,6 +3,7 @@ import branding from courseware.access import has_access from student.models import anonymous_id_for_user +from student.models import UserProfile from user_api.models import UserPreference from lang_pref import LANGUAGE_KEY @@ -33,8 +34,14 @@ class ProfileHandler(object): """ Basic OpenID Connect `profile` scope handler with `locale` claim. """ def scope_profile(self, _data): - """ Add the locale claim. """ - return ['locale'] + """ Add specialized claims. """ + return ['name', 'locale'] + + def claim_name(self, data): + """ User displayable full name. """ + user = data['user'] + profile = UserProfile.objects.get(user=user) + return profile.name def claim_locale(self, data): """ diff --git a/lms/djangoapps/oauth2_handler/tests.py b/lms/djangoapps/oauth2_handler/tests.py index 9b19357dcb..4a545753a4 100644 --- a/lms/djangoapps/oauth2_handler/tests.py +++ b/lms/djangoapps/oauth2_handler/tests.py @@ -6,6 +6,7 @@ from courseware.tests.tests import TEST_DATA_MIXED_MODULESTORE from lang_pref import LANGUAGE_KEY from opaque_keys.edx.locations import SlashSeparatedCourseKey from student.models import anonymous_id_for_user +from student.models import UserProfile from student.roles import CourseStaffRole, CourseInstructorRole from student.tests.factories import UserFactory, UserProfileFactory from user_api.models import UserPreference @@ -42,6 +43,15 @@ class IDTokenTest(BaseTestMixin, IDTokenTestCase): expected_sub = anonymous_id_for_user(self.user, None) self.assertEqual(sub, expected_sub) + def test_user_name_claim(self): + _scopes, claims = self.get_new_id_token_values('openid profile') + claim_name = claims['name'] + + user_profile = UserProfile.objects.get(user=self.user) + user_name = user_profile.name + + self.assertEqual(claim_name, user_name) + def test_user_without_locale_claim(self): scopes, claims = self.get_new_id_token_values('openid profile') self.assertIn('profile', scopes)