2015-06-19 18:19:46 +00:00
|
|
|
import importlib
|
|
|
|
|
2015-01-28 17:50:14 +00:00
|
|
|
from django.conf import settings
|
2015-03-02 20:37:54 +00:00
|
|
|
|
2015-01-28 17:50:14 +00:00
|
|
|
|
2015-03-04 20:17:37 +00:00
|
|
|
class DefaultSettings(object):
|
2015-01-28 17:50:14 +00:00
|
|
|
|
2015-03-04 20:17:37 +00:00
|
|
|
@property
|
|
|
|
def LOGIN_URL(self):
|
|
|
|
"""
|
|
|
|
REQUIRED.
|
|
|
|
"""
|
|
|
|
return None
|
2015-03-02 20:37:54 +00:00
|
|
|
|
2015-03-04 20:17:37 +00:00
|
|
|
@property
|
|
|
|
def SITE_URL(self):
|
|
|
|
"""
|
|
|
|
REQUIRED.
|
|
|
|
"""
|
|
|
|
return None
|
2015-03-02 20:37:54 +00:00
|
|
|
|
2015-03-19 17:04:32 +00:00
|
|
|
@property
|
|
|
|
def OIDC_AFTER_USERLOGIN_HOOK(self):
|
|
|
|
"""
|
|
|
|
OPTIONAL.
|
|
|
|
"""
|
|
|
|
def default_hook_func(request, user, client):
|
|
|
|
return None
|
|
|
|
|
|
|
|
return default_hook_func
|
|
|
|
|
2015-03-04 20:17:37 +00:00
|
|
|
@property
|
|
|
|
def OIDC_CODE_EXPIRE(self):
|
|
|
|
"""
|
|
|
|
OPTIONAL.
|
|
|
|
"""
|
|
|
|
return 60*10
|
2015-02-26 19:14:36 +00:00
|
|
|
|
2015-03-04 20:17:37 +00:00
|
|
|
@property
|
|
|
|
def OIDC_EXTRA_SCOPE_CLAIMS(self):
|
|
|
|
"""
|
|
|
|
OPTIONAL.
|
|
|
|
"""
|
2015-06-19 18:19:46 +00:00
|
|
|
return 'oidc_provider.lib.claims.AbstractScopeClaims'
|
2015-03-04 20:17:37 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def OIDC_IDTOKEN_EXPIRE(self):
|
|
|
|
"""
|
|
|
|
OPTIONAL.
|
|
|
|
"""
|
|
|
|
return 60*10
|
|
|
|
|
|
|
|
@property
|
|
|
|
def OIDC_IDTOKEN_SUB_GENERATOR(self):
|
|
|
|
"""
|
|
|
|
OPTIONAL.
|
|
|
|
"""
|
|
|
|
def default_sub_generator(user):
|
|
|
|
return user.id
|
|
|
|
|
|
|
|
return default_sub_generator
|
|
|
|
|
|
|
|
@property
|
2015-06-24 15:40:00 +00:00
|
|
|
def OIDC_SKIP_CONSENT_ENABLE(self):
|
2015-03-04 20:17:37 +00:00
|
|
|
"""
|
|
|
|
OPTIONAL.
|
|
|
|
"""
|
2015-06-24 15:40:00 +00:00
|
|
|
return True
|
2015-01-28 17:50:14 +00:00
|
|
|
|
2015-06-22 21:41:42 +00:00
|
|
|
@property
|
2015-06-24 15:40:00 +00:00
|
|
|
def OIDC_SKIP_CONSENT_EXPIRE(self):
|
2015-06-22 21:41:42 +00:00
|
|
|
"""
|
|
|
|
OPTIONAL.
|
|
|
|
"""
|
2015-06-24 15:40:00 +00:00
|
|
|
return 30*3
|
2015-06-22 21:41:42 +00:00
|
|
|
|
|
|
|
@property
|
2015-06-24 15:40:00 +00:00
|
|
|
def OIDC_TOKEN_EXPIRE(self):
|
2015-06-22 21:41:42 +00:00
|
|
|
"""
|
|
|
|
OPTIONAL.
|
|
|
|
"""
|
2015-06-24 15:40:00 +00:00
|
|
|
return 60*60
|
2015-06-19 18:19:46 +00:00
|
|
|
|
2015-03-06 15:55:50 +00:00
|
|
|
default_settings = DefaultSettings()
|
2015-03-02 20:37:54 +00:00
|
|
|
|
2015-06-19 18:19:46 +00:00
|
|
|
|
|
|
|
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):
|
|
|
|
"""
|
2015-03-02 20:37:54 +00:00
|
|
|
Helper function to use inside the package.
|
2015-06-19 18:19:46 +00:00
|
|
|
"""
|
2015-03-02 20:37:54 +00:00
|
|
|
try:
|
2015-03-06 15:55:50 +00:00
|
|
|
value = getattr(default_settings, name)
|
2015-03-02 20:37:54 +00:00
|
|
|
value = getattr(settings, name)
|
|
|
|
except AttributeError:
|
|
|
|
if value == None:
|
|
|
|
raise Exception('You must set ' + name + ' in your settings.')
|
|
|
|
|
2015-06-19 18:37:42 +00:00
|
|
|
value = import_from_str(value) if import_str else value
|
|
|
|
|
2015-06-19 18:19:46 +00:00
|
|
|
return value
|