| 1 |
Metadata-Version: 2.4 |
| 2 |
Name: django-auth-ldap |
| 3 |
Version: 5.3.0 |
| 4 |
Summary: Django LDAP authentication backend |
| 5 |
Author-email: Peter Sagerson <[email protected]> |
| 6 |
Maintainer-email: François Freitag <[email protected]> |
| 7 |
License: BSD |
| 8 |
Project-URL: Homepage, https://github.com/django-auth-ldap/django-auth-ldap |
| 9 |
Project-URL: Documentation, https://django-auth-ldap.readthedocs.io/ |
| 10 |
Project-URL: Source, https://github.com/django-auth-ldap/django-auth-ldap |
| 11 |
Project-URL: Tracker, https://github.com/django-auth-ldap/django-auth-ldap/issues |
| 12 |
Project-URL: Changelog, https://github.com/django-auth-ldap/django-auth-ldap/releases/ |
| 13 |
Classifier: Development Status :: 5 - Production/Stable |
| 14 |
Classifier: Environment :: Web Environment |
| 15 |
Classifier: Framework :: Django |
| 16 |
Classifier: Framework :: Django :: 4.2 |
| 17 |
Classifier: Framework :: Django :: 5.2 |
| 18 |
Classifier: Framework :: Django :: 6.0 |
| 19 |
Classifier: Intended Audience :: Developers |
| 20 |
Classifier: Intended Audience :: System Administrators |
| 21 |
Classifier: License :: OSI Approved :: BSD License |
| 22 |
Classifier: Programming Language :: Python |
| 23 |
Classifier: Programming Language :: Python :: 3 |
| 24 |
Classifier: Programming Language :: Python :: 3 :: Only |
| 25 |
Classifier: Programming Language :: Python :: 3.10 |
| 26 |
Classifier: Programming Language :: Python :: 3.11 |
| 27 |
Classifier: Programming Language :: Python :: 3.12 |
| 28 |
Classifier: Programming Language :: Python :: 3.13 |
| 29 |
Classifier: Programming Language :: Python :: 3.14 |
| 30 |
Classifier: Topic :: Internet :: WWW/HTTP |
| 31 |
Classifier: Topic :: Software Development :: Libraries :: Python Modules |
| 32 |
Classifier: Topic :: System :: Systems Administration :: Authentication/Directory :: LDAP |
| 33 |
Requires-Python: >=3.10 |
| 34 |
Description-Content-Type: text/x-rst |
| 35 |
License-File: LICENSE |
| 36 |
Requires-Dist: Django>=4.2 |
| 37 |
Requires-Dist: python-ldap>=3.1 |
| 38 |
Dynamic: license-file |
| 39 |
|
| 40 |
================================ |
| 41 |
Django Authentication Using LDAP |
| 42 |
================================ |
| 43 |
|
| 44 |
.. image:: https://readthedocs.org/projects/django-auth-ldap/badge/?version=latest |
| 45 |
:target: https://django-auth-ldap.readthedocs.io/en/latest/ |
| 46 |
|
| 47 |
.. image:: https://img.shields.io/pypi/v/django-auth-ldap.svg |
| 48 |
:target: https://pypi.org/project/django-auth-ldap/ |
| 49 |
|
| 50 |
.. image:: https://github.com/django-auth-ldap/django-auth-ldap/workflows/Test/badge.svg |
| 51 |
:target: https://github.com/django-auth-ldap/django-auth-ldap/workflows/Test/badge.svg |
| 52 |
|
| 53 |
.. image:: https://img.shields.io/pypi/l/django-auth-ldap.svg |
| 54 |
:target: https://raw.githubusercontent.com/django-auth-ldap/django-auth-ldap/master/LICENSE |
| 55 |
|
| 56 |
This is a Django authentication backend that authenticates against an LDAP |
| 57 |
service. Configuration can be as simple as a single distinguished name |
| 58 |
template, but there are many rich configuration options for working with users, |
| 59 |
groups, and permissions. |
| 60 |
|
| 61 |
* Documentation: https://django-auth-ldap.readthedocs.io/ |
| 62 |
* PyPI: https://pypi.org/project/django-auth-ldap/ |
| 63 |
* Repository: https://github.com/django-auth-ldap/django-auth-ldap |
| 64 |
* License: BSD 2-Clause |
| 65 |
|
| 66 |
.. _`python-ldap`: https://pypi.org/project/python-ldap/ |
| 67 |
|
| 68 |
|
| 69 |
Installation |
| 70 |
============ |
| 71 |
|
| 72 |
Install the package with pip: |
| 73 |
|
| 74 |
.. code-block:: sh |
| 75 |
|
| 76 |
$ pip install django-auth-ldap |
| 77 |
|
| 78 |
It requires `python-ldap`_ >= 3.1. You'll need the `OpenLDAP`_ libraries and |
| 79 |
headers available on your system. |
| 80 |
|
| 81 |
To use the auth backend in a Django project, add |
| 82 |
``'django_auth_ldap.backend.LDAPBackend'`` to ``AUTHENTICATION_BACKENDS``. Do |
| 83 |
not add anything to ``INSTALLED_APPS``. |
| 84 |
|
| 85 |
.. code-block:: python |
| 86 |
|
| 87 |
AUTHENTICATION_BACKENDS = [ |
| 88 |
'django_auth_ldap.backend.LDAPBackend', |
| 89 |
] |
| 90 |
|
| 91 |
``LDAPBackend`` should work with custom user models, but it does assume that a |
| 92 |
database is present. |
| 93 |
|
| 94 |
.. note:: |
| 95 |
|
| 96 |
``LDAPBackend`` does not inherit from ``ModelBackend``. It is possible to |
| 97 |
use ``LDAPBackend`` exclusively by configuring it to draw group membership |
| 98 |
from the LDAP server. However, if you would like to assign permissions to |
| 99 |
individual users or add users to groups within Django, you'll need to have |
| 100 |
both backends installed: |
| 101 |
|
| 102 |
.. code-block:: python |
| 103 |
|
| 104 |
AUTHENTICATION_BACKENDS = [ |
| 105 |
'django_auth_ldap.backend.LDAPBackend', |
| 106 |
'django.contrib.auth.backends.ModelBackend', |
| 107 |
] |
| 108 |
|
| 109 |
.. _`OpenLDAP`: https://www.openldap.org/ |
| 110 |
|
| 111 |
|
| 112 |
Example Configuration |
| 113 |
===================== |
| 114 |
|
| 115 |
Here is a complete example configuration from ``settings.py`` that exercises |
| 116 |
nearly all of the features. In this example, we're authenticating against a |
| 117 |
global pool of users in the directory, but we have a special area set aside for |
| 118 |
Django groups (``ou=django,ou=groups,dc=example,dc=com``). Remember that most |
| 119 |
of this is optional if you just need simple authentication. Some default |
| 120 |
settings and arguments are included for completeness. |
| 121 |
|
| 122 |
.. code-block:: python |
| 123 |
|
| 124 |
import ldap |
| 125 |
from django_auth_ldap.config import LDAPSearch, GroupOfNamesType |
| 126 |
|
| 127 |
|
| 128 |
# Baseline configuration. |
| 129 |
AUTH_LDAP_SERVER_URI = 'ldap://ldap.example.com' |
| 130 |
|
| 131 |
AUTH_LDAP_BIND_DN = 'cn=django-agent,dc=example,dc=com' |
| 132 |
AUTH_LDAP_BIND_PASSWORD = 'phlebotinum' |
| 133 |
AUTH_LDAP_USER_SEARCH = LDAPSearch( |
| 134 |
'ou=users,dc=example,dc=com', |
| 135 |
ldap.SCOPE_SUBTREE, |
| 136 |
'(uid=%(user)s)', |
| 137 |
) |
| 138 |
# Or: |
| 139 |
# AUTH_LDAP_USER_DN_TEMPLATE = 'uid=%(user)s,ou=users,dc=example,dc=com' |
| 140 |
|
| 141 |
# Set up the basic group parameters. |
| 142 |
AUTH_LDAP_GROUP_SEARCH = LDAPSearch( |
| 143 |
'ou=django,ou=groups,dc=example,dc=com', |
| 144 |
ldap.SCOPE_SUBTREE, |
| 145 |
'(objectClass=groupOfNames)', |
| 146 |
) |
| 147 |
AUTH_LDAP_GROUP_TYPE = GroupOfNamesType(name_attr='cn') |
| 148 |
|
| 149 |
# Simple group restrictions |
| 150 |
AUTH_LDAP_REQUIRE_GROUP = 'cn=enabled,ou=django,ou=groups,dc=example,dc=com' |
| 151 |
AUTH_LDAP_DENY_GROUP = 'cn=disabled,ou=django,ou=groups,dc=example,dc=com' |
| 152 |
|
| 153 |
# Populate the Django user from the LDAP directory. |
| 154 |
AUTH_LDAP_USER_ATTR_MAP = { |
| 155 |
'first_name': 'givenName', |
| 156 |
'last_name': 'sn', |
| 157 |
'email': 'mail', |
| 158 |
} |
| 159 |
|
| 160 |
AUTH_LDAP_USER_FLAGS_BY_GROUP = { |
| 161 |
'is_active': 'cn=active,ou=django,ou=groups,dc=example,dc=com', |
| 162 |
'is_staff': 'cn=staff,ou=django,ou=groups,dc=example,dc=com', |
| 163 |
'is_superuser': 'cn=superuser,ou=django,ou=groups,dc=example,dc=com', |
| 164 |
} |
| 165 |
|
| 166 |
# This is the default, but I like to be explicit. |
| 167 |
AUTH_LDAP_ALWAYS_UPDATE_USER = True |
| 168 |
|
| 169 |
# Use LDAP group membership to calculate group permissions. |
| 170 |
AUTH_LDAP_FIND_GROUP_PERMS = True |
| 171 |
|
| 172 |
# Cache distinguished names and group memberships for an hour to minimize |
| 173 |
# LDAP traffic. |
| 174 |
AUTH_LDAP_CACHE_TIMEOUT = 3600 |
| 175 |
|
| 176 |
# Keep ModelBackend around for per-user permissions and maybe a local |
| 177 |
# superuser. |
| 178 |
AUTHENTICATION_BACKENDS = ( |
| 179 |
'django_auth_ldap.backend.LDAPBackend', |
| 180 |
'django.contrib.auth.backends.ModelBackend', |
| 181 |
) |
| 182 |
|
| 183 |
|
| 184 |
Contributing |
| 185 |
============ |
| 186 |
|
| 187 |
If you'd like to contribute, the best approach is to send a well-formed pull |
| 188 |
request, complete with tests and documentation. Pull requests should be |
| 189 |
focused: trying to do more than one thing in a single request will make it more |
| 190 |
difficult to process. |
| 191 |
|
| 192 |
If you have a bug or feature request you can try `logging an issue`_. |
| 193 |
|
| 194 |
There's no harm in creating an issue and then submitting a pull request to |
| 195 |
resolve it. This can be a good way to start a conversation and can serve as an |
| 196 |
anchor point. |
| 197 |
|
| 198 |
.. _`logging an issue`: https://github.com/django-auth-ldap/django-auth-ldap/issues |