简体   繁体   中英

Django authentication LDAP unable to find user

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!

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)")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM