Skip to content

Commit

Permalink
release 1.0.3, added trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
fang.li committed Apr 15, 2016
1 parent 88a0af3 commit b7ddbc0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
32 changes: 29 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
=========
Expand Down
5 changes: 5 additions & 0 deletions django_saml2_auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
Expand Down

0 comments on commit b7ddbc0

Please sign in to comment.