如何使用 Python + LDAP 对 AD 进行身份验证。我目前正在使用 python-ldap 库,它所产生的只是眼泪。
我什至不能绑定(bind)来执行一个简单的查询:
import sys
import ldap
Server = "ldap://my-ldap-server"
DN, Secret, un = sys.argv[1:4]
Base = "dc=mydomain,dc=co,dc=uk"
Scope = ldap.SCOPE_SUBTREE
Filter = "(&(objectClass=user)(sAMAccountName="+un+"))"
Attrs = ["displayName"]
l = ldap.initialize(Server)
l.protocol_version = 3
print l.simple_bind_s(DN, Secret)
r = l.search(Base, Scope, Filter, Attrs)
Type,user = l.result(r,60)
Name,Attrs = user[0]
if hasattr(Attrs, 'has_key') and Attrs.has_key('displayName'):
displayName = Attrs['displayName'][0]
print displayName
sys.exit()
使用 myusername@mydomain.co.uk 密码用户名
运行此程序会出现以下两个错误之一:
Invalid Credentials
- 当我输入错误或故意使用错误的凭据时,它无法进行身份验证。
ldap.INVALID_CREDENTIALS: {'info': '80090308: LdapErr: DSID-0C090334, comment: AcceptSecurityContext error, data 52e, vece', 'desc': 'Invalid credentials'}
或者
ldap.OPERATIONS_ERROR: {'info': '00000000: LdapErr: DSID-0C090627, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, vece', 'desc': 'Operations error'}
我错过了什么才能正确绑定(bind)?
我在 fedora 和 windows 上遇到同样的错误。
最佳答案
我错过了
l.set_option(ldap.OPT_REFERRALS, 0)
从一开始。
关于python - 使用 python + ldap 对事件目录进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/140439/