@@ -510,25 +510,17 @@ https://docs.djangoproject.com/en/dev/topics/auth/customizing/#substituting-a-cu
510
510
511
511
Sometimes you need to use special logic to update the user object
512
512
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::
516
515
517
- from djangosaml2.signals import pre_user_save
516
+ from djangosaml2.backends import Saml2Backend
518
517
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)
531
522
523
+ .. _hooks : https://github.com/knaperek/djangosaml2/blob/master/djangosaml2/backends.py#L181
532
524
533
525
IdP setup
534
526
=========
0 commit comments