Skip to content

Commit

Permalink
LDAP identity provider: add an option to create identity from auth_in…
Browse files Browse the repository at this point in the history
…fo rather than from LDAP

- Config parameter is accepted_users=all
- Allow to support non local (LDAP) users when using a Shibboleth auth provider
  • Loading branch information
Michel Jouvin committed Dec 13, 2023
1 parent ce90347 commit a8ac6d3
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion flask_multipass/providers/ldap/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ def __init__(self, *args, **kwargs):
self._attributes = list(
convert_app_data(self.settings['mapping'], {}, self.settings['identity_info_keys']).values())
self._attributes.append(self.ldap_settings['uid'])
accepted_users = self.settings.setdefault('accepted_users', 'local').lower()
if accepted_users == 'all':
self.id_from_auth = True
else:
self.id_from_auth = False

@property
def supports_get_identity_groups(self):
Expand All @@ -182,7 +187,16 @@ def _search_groups(self, search_filter): # pragma: no cover
return search(self.ldap_settings['group_base'], search_filter, attributes=[self.ldap_settings['gid']])

def get_identity_from_auth(self, auth_info): # pragma: no cover
return self._get_identity(auth_info.data.pop('identifier'))
identifier = auth_info.data.pop('identifier')
if not identifier:
raise IdentityRetrievalFailed('Identifier missing in auth provider response', provider=self)
# Try to get identity attributes from LDAP. If self.id_from_auth=True, and
# the user is not found in LDAP, use the auth_info attributes to create the identity:
# useful when using a Shibboleth auth provider to authenticate local and non local users.
identity = self._get_identity(identifier)
if identity is None and self.id_from_auth:
identity = IdentityInfo(self, identifier=identifier, **auth_info.data)
return identity

def refresh_identity(self, identifier, multipass_data): # pragma: no cover
return self._get_identity(identifier)
Expand Down

0 comments on commit a8ac6d3

Please sign in to comment.