Django user authentication: django_auth_ldap.backend.LDAPBackend

I don't understand how to use LDAPBackend in django, all I want to do is authenticate the user against LDAP. I tried the following:

from django_auth_ldap.backend import LDAPBackend
auth = LDAPBackend()
user = auth.authenticate(username='my_uid',password='pwd')

At this point, the user is None and looks at tcpdump. I do not see attempts to connect to the LDAP server.

settings.py
AUTH_LDAP_SERVER_URI = 'ldap.example.com'
AUTH_LDAP_USER_DN_TEMPLATE = 'uid=%(user)s,ou=People,dc=example,dc=com'
AUTH_LDAP_BIND_AS_AUTHENTICATING_USER = True
AUTH_LDAP_CACHE_GROUPS = True
AUTH_LDAP_GROUP_CACHE_TIMEOUT = 3600
AUTH_LDAP_USER_ATTR_MAP = {
"first_name": "givenName",
"last_name": "sn",
"email": "mail"
}
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'django_auth_ldap.backend.LDAPBackend',
)

The official django doc does not provide any snippet on how to use this backend in a view.

Many thanks for your help!

+5
source share
1 answer

django-auth-ldap . 'django_auth_ldap'; . Django.

, , AUTH_LDAP_SERVER_URI URI; - ldap://ldap.example.com/. AUTH_LDAP_BIND_AS_AUTHENTICATING_USER: , , , .

+1

All Articles