Skip to content

Commit 2f04ff9

Browse files
authored
Documentation: Replace signal with hooks (#251)
1 parent bcdb4cb commit 2f04ff9

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

README.rst

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -510,25 +510,17 @@ https://docs.djangoproject.com/en/dev/topics/auth/customizing/#substituting-a-cu
510510

511511
Sometimes you need to use special logic to update the user object
512512
depending on the SAML2 attributes and the mapping described above
513-
is simply not enough. For these cases djangosaml2 provides a Django
514-
signal that you can listen to. In order to do so you can add the
515-
following code to your app::
513+
is simply not enough. For these cases djangosaml2 provides hooks_
514+
that can be overriden with custom functionality. For example::
516515

517-
from djangosaml2.signals import pre_user_save
516+
from djangosaml2.backends import Saml2Backend
518517

519-
def custom_update_user(sender=User, instance, attributes, user_modified, **kargs)
520-
...
521-
return True # I modified the user object
522-
523-
524-
Your handler will receive the user object, the list of SAML attributes
525-
and a flag telling you if the user is already modified and need
526-
to be saved after your handler is executed. If your handler
527-
modifies the user object it should return True. Otherwise it should
528-
return False. This way djangosaml2 will know if it should save
529-
the user object so you don't need to do it and no more calls to
530-
the save method are issued.
518+
class MySaml2Backend(Saml2Backend):
519+
def save_user(self, user, *args, **kwargs):
520+
# Add custom logic here
521+
return super().save_user(user, *args, **kwargs)
531522

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

533525
IdP setup
534526
=========

0 commit comments

Comments
 (0)