Skip to content

Commit 9f3c6f3

Browse files
authored
docs: add documentation for post_authenticate signal (#351)
* docs: add documentation for post_authenticate signal * PR feedback
1 parent b5e21f6 commit 9f3c6f3

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Contents
3838
settings_ref
3939
config_guides
4040
middleware
41+
signals
4142
rest_framework
4243
demo
4344
troubleshooting

docs/settings_ref.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ ADFS server. Based on this information, certain configuration for this module is
173173
This setting determines the interval after which the configuration is reloaded. This allows to automatically follow the
174174
token signing certificate rollover on ADFS.
175175

176+
.. _create_new_users_setting:
177+
176178
CREATE_NEW_USERS
177179
----------------
178180
* **Default**: ``True``

docs/signals.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Django Signals
2+
================
3+
4+
**django-auth-adfs** uses Django `Signals <https://docs.djangoproject.com/en/stable/topics/signals/>` to allow the
5+
application to listen for and execute custom logic at certain points in the authentication process. Currently, the
6+
following signals are supported:
7+
8+
* ``post_authenticate``: sent after a user has been authenticated through any subclass of ``AdfsBaseBackend``. The
9+
signal is sent after all other processing is done, e.g. mapping claims and groups and creating the user in Django (if
10+
:ref:`the CREATE_NEW_USERS setting <create_new_users_setting>` is enabled). In addition to the sender, the signal
11+
includes the user object, the claims dictionary, and the ADFS response as arguments for the signal handler:
12+
13+
* ``sender`` (``AdfsBaseBackend``): the backend instance from which the signal was triggered.
14+
* ``user`` (Django user class): the user object that was authenticated.
15+
* ``claims`` (``dict``): the decoded access token JWT, which contains all claims sent from the identity provider.
16+
* ``adfs_response`` (``dict|None``): used in the ``AdfsAuthCodeBackend`` to provide the full response received from
17+
the server when exchanging an authorization code for an access token.
18+
19+
To use a signal in your application:
20+
21+
.. code-block:: python
22+
23+
from django.dispatch import receiver
24+
from django_auth_adfs.signals import post_authenticate
25+
26+
27+
@receiver(post_authenticate)
28+
def handle_post_authenticate(sender, user, claims, adfs_response=None, **kwargs):
29+
user.do_post_auth_steps(claims, adfs_response)
30+
31+

0 commit comments

Comments
 (0)