Kenzo_Gilead
Kenzo_Gilead

Reputation: 2439

Django Auth is not finding User Account in LDAP

Morning,

I´m implementing Django Auth Ldap in my proyect but it is not working. I checked ldap connection (by Django shell) and returns a search, so I guess python-ldap is working. I used the next:

import ldap
con = ldap.initialize("ldap://hostname")
con.simple_bind_s( "CN=MyName MySurname, CN=Users, DC=CompanyName, DC=local", "MyPassword" )
con.search_s( 'DC=CompanyName, DC=local', ldap.SCOPE_SUBTREE, '(objectclass=person)', ['sn'] )

When I try to authenticate an user by web (using Django-Auth-Ldap), authentication always returns None.

Settings. (LDAP Configuration).
AUTH_LDAP_SERVER_URI = "ldap://hostname"
AUTH_LDAP_BIND_DN = "CN=MyName MySurname, CN=Users, DC=CompanyName, DC=local"
AUTH_LDAP_BIND_PASSWORD = "MyPassword"
AUTH_LDAP_USER_SEARCH = LDAPSearch("CN=Users, DC=CompanyName, DC=local", ldap.SCOPE_SUBTREE, "(uid=%(user)s)")
AUTH_LDAP_CONNECTION_OPTIONS = {
    ldap.OPT_REFERRALS: False
}

from django_auth_ldap.backend import LDAPBackend
View.
def Login(request):
 usr = "MyUserName"
 pwd = "MyPassword"

    if request.method == 'POST':
        ldap_backend = LDAPBackend()
        user = ldap_backend.authenticate(usr, pwd)
        print user
        print usr, pwd

In my view, I´m passing to the ldap authentication my user and password which I used for login in the domain. Is that correct? I got the value "CN=MyName MySurname, CN=Users, DC=CompanyName, DC=local" from a command in Directory Active server, kind of: dsquery user

This is the AD Schema: AD Structure

What Am I Doing wrong?

Thanks guys.

EDITED: The problem is when I define the search throug uid, if I define it as AUTH_LDAP_USER_SEARCH = LDAPSearch("CN=Users, DC=CompanyName, DC=local", ldap.SCOPE_SUBTREE, "(CN=%(user)s)") is working (and, in the view, I must to pass as usr = "MyNameMySurname" instead). How can I Define the search through the username which I used for login it.

Upvotes: 0

Views: 1565

Answers (1)

Kenzo_Gilead
Kenzo_Gilead

Reputation: 2439

Finally... I must to use samAccountName instead of CN. I hope it help you all. Thanks guys.

Upvotes: 1

Related Questions