Skip to main content

django-python3-ldap

django-python3-ldap provides a Django LDAP user authentication backend for Python 3.

Features

  • Authenticate users with an LDAP server.

  • Sync LDAP users with a local Django database.

  • Supports custom Django user models.

  • Works in Python 3!

Installation

  1. Install using pip install django-python3-ldap.

  2. Add 'django_python3_ldap' to your INSTALLED_APPS setting.

  3. Set your AUTHENTICATION_BACKENDS setting to ("django_python3_ldap.auth.LDAPBackend",)

  4. Configure the settings for your LDAP server (see Available settings, below).

  5. Optionally, run ./manage.py ldap_sync_users to perform an initial sync of LDAP users.

Available settings

# The URL of the LDAP server.
LDAP_AUTH_URL = "ldap://localhost:389"

# The LDAP search base for looking up users.
LDAP_AUTH_SEARCH_BASE = "ou=people,dc=example,dc=com"

# The LDAP class that represents a user.
LDAP_AUTH_OBJECT_CLASS = "inetOrgPerson"

# User model fields mapped to the LDAP
# attributes that represent them.
LDAP_AUTH_USER_FIELDS = {
    "username": "uid",
    "first_name": "givenName",
    "last_name": "sn",
    "email": "mail",
}

# A tuple of fields used to uniquely identify a user.
LDAP_AUTH_USER_LOOKUP_FIELDS = ("username",)

# Callable that transforms the user data loaded from
# LDAP into a form suitable for creating a user.
# Override this to set custom field formatting for your
# user model.
LDAP_AUTH_CLEAN_USER_DATA = django_python3_ldap.utils.clean_user_data

How it works

When a user attempts to authenticate, a connection is made to the LDAP server, and the application attempts to bind using the provided username and password.

If the bind attempt is successful, the user details are loaded from the LDAP server and saved in a local Django User model. The local model is only created once, and the details will be kept updated with the LDAP record details on every login.

To perform a full sync of all LDAP users to the local database, run ./manage.py ldap_sync_users. This is not required, as the authentication backend will create users on demand. Syncing users has the advantage of allowing you to assign permissions and groups to the existing users using the Django admin interface.

Running ldap_sync_users as a background cron task is another optional way to keep all users in sync on a regular basis.

Support and announcements

Downloads and bug tracking can be found at the main project website.

More information

The django-python3-ldap project was developed by Dave Hall. You can get the code from the django-python3-ldap project site.

Dave Hall is a freelance web developer, based in Cambridge, UK. You can usually find him on the Internet in a number of different places:

Metadata

Release files for django-python3-ldap 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-python3-ldap 0.9.0
File Size Uploaded Provenance Actions
django-python3-ldap-0.9.0.tar.gz 7.6 kB Without provenance Details for django-python3-ldap-0.9.0.tar.gz

Release files / django-python3-ldap-0.9.0.tar.gz

Download URL django-python3-ldap-0.9.0.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d21f981e91560b1f48e58c47e3bf00eb69506bd5ce06b379d072fe535a0c435d
BLAKE2b-256 checksum
How to use checksums
4af411b17271e2e83748bce4a996fd22f41df74cb9de4b18dde51ee2233b3ba0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-python3-ldap 0.9.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.9.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page