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

LDAP identity provider: fix support of an associated Shibboleth auth provider #42

Merged
merged 3 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions flask_multipass/providers/ldap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Flask-Multipass is free software; you can redistribute it
# and/or modify it under the terms of the Revised BSD License.

from .providers import LDAPAuthProvider, LDAPGroup, LDAPIdentityProvider
from .providers import LDAPAuthProvider, LDAPGroup, LDAPIdentityProvider, AuthFallbackLDAPIdentityProvider


__all__ = ('LDAPAuthProvider', 'LDAPGroup', 'LDAPIdentityProvider')
__all__ = ('LDAPAuthProvider', 'LDAPGroup', 'LDAPIdentityProvider', 'AuthFallbackLDAPIdentityProvider')
20 changes: 20 additions & 0 deletions flask_multipass/providers/ldap/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,23 @@ def search_groups(self, name, exact=False):
for group_dn, group_data in self._search_groups(search_filter):
group_name = to_unicode(group_data[self.ldap_settings['gid']][0])
yield self.group_class(self, group_name, group_dn)


class AuthFallbackLDAPIdentityProvider(LDAPIdentityProvider):
"""Provides identity information using LDAP with a fallback to auth provider data.

This identity provider is meant to be used together with an auth provider that provides
all the required data (in particular the Shibboleth provider).

By default it will use only the identifier from the auth provider and look up all the data
from LDAP.

In case the user does not have data in LDAP however, the data provided from the auth provider
will be used.
"""

def get_identity_from_auth(self, auth_info):
identifier = auth_info.data.get('identifier')
if identity := super().get_identity_from_auth(auth_info):
return identity
return IdentityInfo(self, identifier=identifier, **auth_info.data)
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ flask_multipass.auth_providers =
static = flask_multipass.providers.static:StaticAuthProvider
flask_multipass.identity_providers =
ldap = flask_multipass.providers.ldap:LDAPIdentityProvider
ldap_or_authinfo = flask_multipass.providers.ldap:AuthFallbackLDAPIdentityProvider
authlib = flask_multipass.providers.authlib:AuthlibIdentityProvider
saml = flask_multipass.providers.saml:SAMLIdentityProvider
shibboleth = flask_multipass.providers.shibboleth:ShibbolethIdentityProvider
Expand Down