Make OIDC_AFTER_USERLOGIN_HOOK to be lazy imported by string.

This commit is contained in:
juanifioren 2016-01-19 17:37:32 -03:00
parent 889eb47c16
commit 73ece1bf64
4 changed files with 17 additions and 14 deletions

View file

@ -56,3 +56,10 @@ def default_sub_generator(user):
Default function for setting OIDC_IDTOKEN_SUB_GENERATOR. Default function for setting OIDC_IDTOKEN_SUB_GENERATOR.
""" """
return str(user.id) return str(user.id)
def default_after_userlogin_hook(request, user, client):
"""
Default function for setting OIDC_AFTER_USERLOGIN_HOOK.
"""
return None

View file

@ -25,10 +25,7 @@ class DefaultSettings(object):
OPTIONAL. Provide a way to plug into the process after OPTIONAL. Provide a way to plug into the process after
the user has logged in, typically to perform some business logic. the user has logged in, typically to perform some business logic.
""" """
def default_hook_func(request, user, client): return 'oidc_provider.lib.utils.common.default_after_userlogin_hook'
return None
return default_hook_func
@property @property
def OIDC_CODE_EXPIRE(self): def OIDC_CODE_EXPIRE(self):

View file

@ -13,11 +13,11 @@ DATABASES = {
SITE_ID = 1 SITE_ID = 1
MIDDLEWARE_CLASSES = ( MIDDLEWARE_CLASSES = [
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
) ]
LOGGING = { LOGGING = {
'version': 1, 'version': 1,
@ -35,24 +35,23 @@ LOGGING = {
}, },
} }
INSTALLED_APPS = ( INSTALLED_APPS = [
'django.contrib.auth', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.sites', 'django.contrib.sites',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.admin', 'django.contrib.admin',
'oidc_provider', 'oidc_provider',
) ]
SECRET_KEY = 'this-is-top-secret' SECRET_KEY = 'this-should-be-top-secret'
ROOT_URLCONF = 'oidc_provider.tests.app.urls' ROOT_URLCONF = 'oidc_provider.tests.app.urls'
TEMPLATE_DIRS = ( TEMPLATE_DIRS = [
"oidc_provider/tests/templates", 'oidc_provider/tests/templates',
) ]
# OIDC Provider settings. # OIDC Provider settings.

View file

@ -32,7 +32,7 @@ class AuthorizeView(View):
if request.user.is_authenticated(): if request.user.is_authenticated():
# Check if there's a hook setted. # Check if there's a hook setted.
hook_resp = settings.get('OIDC_AFTER_USERLOGIN_HOOK')( hook_resp = settings.get('OIDC_AFTER_USERLOGIN_HOOK', import_str=True)(
request=request, user=request.user, request=request, user=request.user,
client=authorize.client) client=authorize.client)
if hook_resp: if hook_resp: