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

Allow SAML_USERS_LOOKUP_ATTRIBUTE[1] to be callable #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 8 additions & 3 deletions src/saml2_pro_auth/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,15 @@ def authenticate(self, request, saml_auth=None, user_map=dict()):
if isinstance(lookup_attr, str):
lookup_map = {lookup_attr: saml_auth.get_nameid()}
elif isinstance(lookup_attr, (tuple, list)):
if lookup_attr[1] == "NameId":
lookup_map = {lookup_attr[0]: saml_auth.get_nameid()}
lookup_val = lookup_attr[1]
lookup_res = None
if lookup_val == "NameId":
lookup_res = saml_auth.get_nameid()
elif callable(lookup_val):
lookup_res = lookup_val(saml_auth, final_map)
Copy link
Member

Choose a reason for hiding this comment

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

It looks like the callable will have a standard signature. Can we get this documented and an example added for how to use this?

else:
lookup_map = {lookup_attr[0]: final_map[lookup_attr[1]]}
final_map[lookup_val]
Copy link
Member

Choose a reason for hiding this comment

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

Should this be assigning final_map[lookup_val] to lookup_res?

lookup_map = { lookup_attr[0]: lookup_res }
else:
raise SAMLSettingsError(
"The value of SAML_USERS_LOOKUP_ATTRIBUTE must be a str, tuple, or list"
Expand Down