Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a new "AFTER_LOGIN" hook that is called after the user is logged in #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ Contributors
- `Ryan Mahaffey <https://github.com/mahaffey>`_
- `ayr-ton <https://github.com/ayr-ton>`_
_ `kevPo <https://github.com/kevPo>`_
_ `Alex Azevedo <https://github.com/alexazevedo>`_
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ How to use?
'TRIGGER': {
'CREATE_USER': 'path.to.your.new.user.hook.method',
'BEFORE_LOGIN': 'path.to.your.login.hook.method',
'AFTER_LOGIN': 'path.to.your.after.login.hook.method',
},
'ASSERTION_URL': 'https://mysite.com', # Custom URL to validate incoming SAML requests against
'ENTITY_ID': 'https://mysite.com/saml2_auth/acs/', # Populates the Issuer element in authn request
Expand Down Expand Up @@ -196,6 +197,10 @@ record is created. This method should accept ONE parameter of user dict.
This method will be called before the user is logged in and after user
attributes are returned by the SAML2 identity provider. This method should accept ONE parameter of user dict.

**TRIGGER.AFTER_LOGIN** A method to be called when an existing user logs in.
This method will be called after the user is logged in and after user
attributes are returned by the SAML2 identity provider. This method should accept ONE parameter of user dict.

**ASSERTION_URL** A URL to validate incoming SAML responses against. By default,
django-saml2-auth will validate the SAML response's Service Provider address
against the actual HTTP request's host and scheme. If this value is set, it
Expand Down
4 changes: 4 additions & 0 deletions django_saml2_auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ def acs(r):
if target_user.is_active:
target_user.backend = 'django.contrib.auth.backends.ModelBackend'
login(r, target_user)

if settings.SAML2_AUTH.get('TRIGGER', {}).get('AFTER_LOGIN', None):
import_string(settings.SAML2_AUTH['TRIGGER']['AFTER_LOGIN'])(user_identity)

else:
return HttpResponseRedirect(get_reverse([denied, 'denied', 'django_saml2_auth:denied']))

Expand Down