From b7ddbc025622364027f72f644beb994c7976fee2 Mon Sep 17 00:00:00 2001 From: "fang.li" Date: Fri, 15 Apr 2016 15:29:32 +0800 Subject: [PATCH] release 1.0.3, added trigger --- README.rst | 32 +++++++++++++++++++++++++++++--- django_saml2_auth/views.py | 5 +++++ setup.py | 4 ++-- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index c0e5729..61f9b86 100644 --- a/README.rst +++ b/README.rst @@ -3,7 +3,7 @@ Django SAML2 Authentication Made Easy ===================================== :Author: Fang Li -:Version: 1.0.2 +:Version: 1.0.3 .. image:: https://img.shields.io/pypi/pyversions/django-saml2-auth.svg :target: https://pypi.python.org/pypi/django-saml2-auth @@ -83,12 +83,15 @@ How to use? #. In settings.py, add SAML2 related configuration. - Please note only METADATA_AUTO_CONF_URL is required. The following block just shows the full featured configuration and their default values. + Please note only **METADATA_AUTO_CONF_URL** is required. The following block just shows the full featured configuration and their default values. .. code-block:: python SAML2_AUTH = { + # Required 'METADATA_AUTO_CONF_URL': '[The auto(dynamic) metadata configuration URL of SAML2]', + + # Following optional 'NEW_USER_PROFILE': { 'USER_GROUPS': [], # The default group name when a new user logged in 'ACTIVE_STATUS': True, # The default active status of new user @@ -100,12 +103,35 @@ How to use? 'username': 'UserName', 'first_name': 'FirstName', 'last_name': 'LastName', - } + }, + 'TRIGGER': { + 'CREATE_USER': 'path.to.your.new.user.hook.method', + 'BEFORE_LOGIN': 'path.to.your.login.hook.method', + }, } #. In your SAML2 SSO service provider, set Single-sign-on URL and Audience URI(SP Entity ID) to http://your-domain/saml2_auth/acs/ +Explanation +----------- + +**METADATA_AUTO_CONF_URL** Auto SAML2 metadata configuration URL + +**NEW_USER_PROFILE** Everytime when a new user login, we will create the user with this default options in system. + +**ATTRIBUTES_MAP** map django user attributes to SAML2 user attributes. + +**TRIGGER** If you want to do some additional actions, just use trigger. + +**TRIGGER.CREATE_USER** Dot-separated style string, path to a method which receiving ONE dict parameter. This method will be triggered when a **new** +user login, before we logged in this user, after we created the user with default options. You may want to run some new-user-related tasks in this trigger. + +**TRIGGER.BEFORE_LOGIN** Similar to CREATE_USER, but will be triggered only when an **existed** user login, before we logged in this user, after we got +attributes from okta. You may want to update user information before a user logged-in in this trigger. + + + Customize ========= diff --git a/django_saml2_auth/views.py b/django_saml2_auth/views.py index 84c96dc..43461b6 100644 --- a/django_saml2_auth/views.py +++ b/django_saml2_auth/views.py @@ -20,6 +20,7 @@ from django.views.decorators.csrf import csrf_exempt from django.template import TemplateDoesNotExist from django.http import HttpResponseRedirect +from django.utils.module_loading import import_string def get_current_domain(r): @@ -117,8 +118,12 @@ def acs(r): try: target_user = User.objects.get(username=user_name) + if settings.SAML2_AUTH.get('TRIGGER', {}).get('BEFORE_LOGIN', None): + import_string(settings.SAML2_AUTH['TRIGGER']['BEFORE_LOGIN'])(user_identity) except User.DoesNotExist: target_user = _create_new_user(user_name, user_email, user_first_name, user_last_name) + if settings.SAML2_AUTH.get('TRIGGER', {}).get('CREATE_USER', None): + import_string(settings.SAML2_AUTH['TRIGGER']['CREATE_USER'])(user_identity) is_new_user = True r.session.flush() diff --git a/setup.py b/setup.py index 7f31051..d3573d2 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ setup( name='django_saml2_auth', - version='1.0.2', + version='1.0.3', description='Django SAML2 Authentication Made Easy, integrate with SAML2 SSO such as Okta easily', long_description=long_description, @@ -32,7 +32,7 @@ # 3 - Alpha # 4 - Beta # 5 - Production/Stable - 'Development Status :: 4 - Beta', + 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', 'Topic :: Software Development :: Libraries :: Python Modules',