0
votes

I'm working on a django project and I'm trying to authenticate my APP against LDAP server. settings.py:

AUTH_LDAP_SERVER_URI = "ldap://domain.local"
AUTH_LDAP_BIND_DN = "domain\django"
AUTH_LDAP_BIND_PASSWORD = "<Password>"

AUTH_LDAP_USER_SEARCH = LDAPSearch("cn=Users,dc=domain,dc=local",
    ldap.SCOPE_SUBTREE, "(uid=%(user)s)")

AUTHENTICATION_BACKENDS = (
    'django_auth_ldap.backend.LDAPBackend',
    'django.contrib.auth.backends.ModelBackend',
    )

Code:

from django_auth_ldap.backend import LDAPBackend
auth = LDAPBackend()
auth.authenticate(username="omers", password="<password>")

For now I'm just using the shell

When I do tcpdump I see the LDAP packet but for some reason the LDAP server can't find my user but I know it's exist, what am I missing?

Thanks!

1
be careful about that string: "domain\django". Should be r"domain\django" (in that case it works, though). And can you post the error message? - Jean-François Fabre
Hi, I don't know where the error message is, just did a tcpdump.. - omers

1 Answers

1
votes

Ok, I found the answer, my AD doesn't use UID but CN so instead of

AUTH_LDAP_USER_SEARCH = LDAPSearch("cn=Users,dc=domain,dc=local",
ldap.SCOPE_SUBTREE, "(uid=%(user)s)")

I used

AUTH_LDAP_USER_SEARCH = LDAPSearch("cn=Users,dc=domain,dc=local",
ldap.SCOPE_SUBTREE, "(cn=%(user)s)")