Skip to content

Documentation #301

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

Merged
merged 6 commits into from
Jun 27, 2021
Merged
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
30 changes: 23 additions & 7 deletions docs/source/contents/setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -380,19 +380,35 @@ Learn more about Django profile models at:
https://docs.djangoproject.com/en/dev/topics/auth/customizing/#substituting-a-custom-user-model


Custom user attributes processing
---------------------------------

Sometimes you need to use special logic to update the user object
depending on the SAML2 attributes and the mapping described above
is simply not enough. For these cases djangosaml2 provides hooks_
that can be overriden with custom functionality. For example::
that can be overriden with custom functionality.

First of all reference the modified Saml2Backend in settings.py file::


AUTHENTICATION_BACKENDS = [
'your_package.authentication.ModifiedSaml2Backend',
]


For example::

from djangosaml2.backends import Saml2Backend

from djangosaml2.backends import Saml2Backend
class ModifiedSaml2Backend(Saml2Backend):
def save_user(self, user, *args, **kwargs):
user.save()
user_group = Group.objects.get(name='Default')
user.groups.add(user_group)
return super().save_user(user, *args, **kwargs)

class MySaml2Backend(Saml2Backend):
def save_user(self, user, *args, **kwargs):
# Add custom logic here
return super().save_user(user, *args, **kwargs)
.. _hooks: https://github.com/identitypython/djangosaml2/blob/master/djangosaml2/backends.py#L181

.. _hooks: https://github.com/knaperek/djangosaml2/blob/master/djangosaml2/backends.py#L181


URLs
Expand Down