diff --git a/oidc_provider/lib/claims.py b/oidc_provider/lib/claims.py index 28c4602..32c7b27 100644 --- a/oidc_provider/lib/claims.py +++ b/oidc_provider/lib/claims.py @@ -68,7 +68,7 @@ class ScopeClaims(object): """ scopes = [] - for name in self.__class__.__dict__: + for name in dir(self.__class__): if name.startswith('scope_'): scope = name.split('scope_')[1] scopes.append(scope) @@ -98,7 +98,7 @@ class ScopeClaims(object): scopes = [] scopes_info = [] - for name in cls.__dict__: + for name in dir(cls): if name.startswith('info_'): scope_name = name.split('info_')[1] if scope_name in scopes: diff --git a/oidc_provider/tests/cases/test_claims.py b/oidc_provider/tests/cases/test_claims.py index c1ac794..4c274dc 100644 --- a/oidc_provider/tests/cases/test_claims.py +++ b/oidc_provider/tests/cases/test_claims.py @@ -12,7 +12,7 @@ class ClaimsTestCase(TestCase): def setUp(self): self.user = create_fake_user() - self.scopes = ['openid', 'address', 'email', 'phone', 'profile'] + self.scopes = ['openid', 'address', 'email', 'phone', 'profile', 'foo'] self.client = create_fake_client('code') self.token = create_fake_token(self.user, self.scopes, self.client) self.scopeClaims = ScopeClaims(self.token) @@ -62,3 +62,25 @@ class ClaimsTestCase(TestCase): def test_locale(self): with override_language('fr'): self.assertEqual(text_type(StandardScopeClaims.info_profile[0]), 'Profil de base') + + def test_scopeclaims_class_inheritance(self): + # Generate example class that will be used for `OIDC_EXTRA_SCOPE_CLAIMS` setting. + class CustomScopeClaims(ScopeClaims): + + info_foo = ('Title', 'Description') + + def scope_foo(self): + dic = {'test': self.user.id} + return dic + + info_notadd = ('Title', 'Description') + + def scope_notadd(self): + dic = {'test': self.user.id} + return dic + + claims = CustomScopeClaims(self.token) + response = claims.create_response_dic() + + self.assertTrue('test' in response.keys()) + self.assertFalse('notadd' in response.keys())