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

Implemented functionalities to allow multiple LDAP configs #281

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Riccardo-Maffei
Copy link

@Riccardo-Maffei Riccardo-Maffei commented Nov 8, 2024

Hey there! I had to use multiple configurations for my Django Application and i was already using this package, so I tried to implement the functionality myself. I've tested it a bit and up until now it seems to be working, but documentation is still mostly missing.

With this implementation, the user would need to implement a subclass of the LDAP Backend class

class MyBackend(LDAPBackend):
    PREFIX = 'MY_PREFIX_'

and add the required data to settings.py. If the value of a specific setting does not change across LDAP Backends, the user can stick to the default name (no prefix). Thanks to this feature, the new code is entirely compatible with programs that use previous versions of the python3-ldap package.

AUTHENTICATION_BACKENDS = [
    'custom_backends.MyBackend',
    'django_python3_ldap.auth.LDAPBackend',
    'django.contrib.auth.backends.ModelBackend',
]

# Uses different configs for each Backend
LDAP_AUTH_URL = 'ldap://my_ldap:1234'
MY_PREFIX_LDAP_AUTH_URL = f'ldap://my_other_ldap:4321'

# Uses same config for both Backends
LDAP_AUTH_OBJECT_CLASS = '*'

What do you think about it?

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.

1 participant