python - 使用 python + ldap 对事件目录进行身份验证

标签 python authentication active-directory ldap

如何使用 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/

相关文章:

python - 想知道 GeoDjango 和 map 服务

解析此字符串的 Pythonic 方式?

regex - 正则表达式到/var/log/secure中的数学身份验证失败

python - 从 Python 和 impacket 获取 TCP 数据包有效载荷

php - HTTP 基本身份验证与 key

ruby-on-rails - before_filter:authenticate_user !,除了:[:index]/Rails 4

.net - 在 Silverlight/.NET Web 应用程序上启用 SSO : NTLM?

.net - 当调用者不在域中时请求用户在 AD 中的角色

azure - 有关使用 Active Directory 实现 azure ACS 的示例或分步教程

python - Django读取excel(xlsx)文件以显示在表格中