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

docs: add documentation for post_authenticate signal #351

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ajw725
Copy link

@ajw725 ajw725 commented Oct 17, 2024

I fumbled around for a while trying to figure out how to execute some custom code after a user is created/authenticated via SSO before I found the post_authenticate signal in the source code. I didn't see it in the docs, and having it in there would have saved me some time.

I didn't really think it fit into any of the existing sections, but if you'd prefer it to be in there (maybe under installation, I guess?), let me know and I can move it.

@JonasKs
Copy link
Member

JonasKs commented Oct 17, 2024

Thanks! This looks good to me☺️

Copy link
Member

@tim-schilling tim-schilling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great to have, thank you! Let me know what you think of my suggestions. If you don't have time to implement them, I can help.

Comment on lines +8 to +9
* ``post_authenticate``: sent after a user has been authenticated through either the ``AdfsAuthCodeBackend``
or the ``AdfsAccessTokenBackend`` (and created in Django, if ``CREATE_NEW_USERS`` is enabled) and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with this being merged as is, but I think there's room for some improvement.

I haven't checked the code, but I'm pretty sure the base backend class is what triggers the signal. If that's true it's better to say "authenticated through any subclass of BaseBackend (use the actual name). This signal is sent after any processing is done such as mapping claims, groups and creating the user if CREATE_NEW_USERS is enabled."

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are correct - i was looking at something else in the subclasses and just misremembered when i was writing this. i'll update it.

process. Currently, the following signals are supported:

* ``post_authenticate``: sent after a user has been authenticated through either the ``AdfsAuthCodeBackend``
or the ``AdfsAccessTokenBackend`` (and created in Django, if ``CREATE_NEW_USERS`` is enabled) and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we'd put a ref on CREATE_NEW_USERS in settings_ref.rst and use the ref syntax here.

@receiver(post_authenticate)
def handle_post_authenticate(sender, user, claims, adfs_response, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would there be a benefit to explaining what the signal arguments are outside the code block?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was a little torn on adding more documentation here vs. adding another place that needs to be changed if the code changes. but i guess if there's going to be a doc for it, it might as well be descriptive.

Copy link
Author

@ajw725 ajw725 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i can implement those, no problem. should be able to get to it this weekend if not before. thanks for the suggestions!

Comment on lines +8 to +9
* ``post_authenticate``: sent after a user has been authenticated through either the ``AdfsAuthCodeBackend``
or the ``AdfsAccessTokenBackend`` (and created in Django, if ``CREATE_NEW_USERS`` is enabled) and
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are correct - i was looking at something else in the subclasses and just misremembered when i was writing this. i'll update it.

@receiver(post_authenticate)
def handle_post_authenticate(sender, user, claims, adfs_response, **kwargs):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was a little torn on adding more documentation here vs. adding another place that needs to be changed if the code changes. but i guess if there's going to be a doc for it, it might as well be descriptive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants