Authenticating against active directory using python + ldap

后端 未结 11 1055
孤街浪徒
孤街浪徒 2020-11-28 17:48

How do I authenticate against AD using Python + LDAP. I\'m currently using the python-ldap library and all it is producing is tears.

I can\'t even bind to perform a

相关标签:
11条回答
  • 2020-11-28 18:13

    I had the same issue, but it was regarding the password encoding

    .encode('iso-8859-1')
    

    Solved the problem.

    0 讨论(0)
  • 2020-11-28 18:13

    Use a Distinguished Name to log on your system."CN=Your user,CN=Users,DC=b2t,DC=local" It should work on any LDAP system, including AD

    0 讨论(0)
  • 2020-11-28 18:14

    I see your comment to @Johan Buret about the DN not fixing your problem, but I also believe that is what you should look into.

    Given your example, the DN for the default administrator account in AD will be: cn=Administrator,cn=Users,dc=mydomain,dc=co,dc=uk - please try that.

    0 讨论(0)
  • 2020-11-28 18:22

    I was missing

    l.set_option(ldap.OPT_REFERRALS, 0)
    

    From the init.

    0 讨论(0)
  • 2020-11-28 18:23

    If you are open to using pywin32, you can use Win32 calls from Python. This is what we do in our CherryPy web server:

    import win32security
    token = win32security.LogonUser(
        username,
        domain,
        password,
        win32security.LOGON32_LOGON_NETWORK,
        win32security.LOGON32_PROVIDER_DEFAULT)
    authenticated = bool(token)
    
    0 讨论(0)
  • 2020-11-28 18:26

    if you have Kerberos installed and talking to AD, as would be the case with, say, Centrify Express installed and running, you might just use python-kerberos. E.g.

    import kerberos
    kerberos.checkPassword('joe','pizza','krbtgt/x.pizza.com','X.PIZZA.COM')`
    

    would return True a user 'joe' has password 'pizza' in the Kerberos realm X.PIZZA.COM. (typically, I think, the latter would be the same as the name of the AD Domain)

    0 讨论(0)
提交回复
热议问题