Now OIDC_EXTRA_SCOPE_CLAIMS must be a string (lazy imported).

This commit is contained in:
juanifioren 2015-06-19 15:19:46 -03:00
parent 0a0db22997
commit bcb144dcdb
2 changed files with 26 additions and 8 deletions

View file

@ -66,7 +66,7 @@ class UserInfoEndpoint(object):
dic.update(standard_claims.create_response_dic()) dic.update(standard_claims.create_response_dic())
extra_claims = settings.get('OIDC_EXTRA_SCOPE_CLAIMS')( extra_claims = settings.get('OIDC_EXTRA_SCOPE_CLAIMS', import_str=True)(
self.token.user, self.token.scope) self.token.user, self.token.scope)
dic.update(extra_claims.create_response_dic()) dic.update(extra_claims.create_response_dic())

View file

@ -1,3 +1,5 @@
import importlib
from django.conf import settings from django.conf import settings
@ -39,9 +41,7 @@ class DefaultSettings(object):
""" """
OPTIONAL. OPTIONAL.
""" """
from oidc_provider.lib.claims import AbstractScopeClaims return 'oidc_provider.lib.claims.AbstractScopeClaims'
return AbstractScopeClaims
@property @property
def OIDC_IDTOKEN_EXPIRE(self): def OIDC_IDTOKEN_EXPIRE(self):
@ -67,17 +67,35 @@ class DefaultSettings(object):
""" """
return 60*60 return 60*60
default_settings = DefaultSettings() default_settings = DefaultSettings()
def get(name):
''' def import_from_str(value):
"""
Attempt to import a class from a string representation.
"""
try:
parts = value.split('.')
module_path, class_name = '.'.join(parts[:-1]), parts[-1]
module = importlib.import_module(module_path)
return getattr(module, class_name)
except ImportError as e:
msg = 'Could not import %s for settings. %s: %s.' % (value, e.__class__.__name__, e)
raise ImportError(msg)
def get(name, import_str=False):
"""
Helper function to use inside the package. Helper function to use inside the package.
''' """
try: try:
value = getattr(default_settings, name) value = getattr(default_settings, name)
value = getattr(settings, name) value = getattr(settings, name)
if import_str:
value = import_from_str(value)
except AttributeError: except AttributeError:
if value == None: if value == None:
raise Exception('You must set ' + name + ' in your settings.') raise Exception('You must set ' + name + ' in your settings.')
return value return value