【问题标题】:django-auth-ldap installation not workingdjango-auth-ldap 安装不工作
【发布时间】:2019-06-11 23:43:54
【问题描述】:

我正在尝试在我的 Windows 系统中安装 django-auth-ldap 它显示以下错误

\pip-build-3x6rkxb4\pyldap\modules\errors.h(8):致命错误 C1083:无法打开包含文件:'lber.h':没有这样的文件或目录 错误:命令 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe' 失败,退出状态为 2

# LDAP auth settings.
LDAP_AUTH_URL = os.environ.get("LDAP_AUTH_URL", "ldap://xxx.xx.xx.xx:389")
LDAP_AUTH_USE_TLS = False

LDAP_AUTH_SEARCH_BASE = "dc=maxcrc,dc=com" 
LDAP_AUTH_OBJECT_CLASS = "inetOrgPerson"
LDAP_AUTH_USER_FIELDS = {
    "username": "uid",
    "first_name": "givenName",
    "last_name": "sn",
    "email": "mail",
}
LDAP_AUTH_USER_LOOKUP_FIELDS = ("username",)
LDAP_AUTH_CLEAN_USER_DATA = "django_python3_ldap.utils.clean_user_data"
LDAP_AUTH_SYNC_USER_RELATIONS = "django_python3_ldap.utils.sync_user_relations"
LDAP_AUTH_FORMAT_SEARCH_FILTERS = "django_python3_ldap.utils.format_search_filters"
LDAP_AUTH_FORMAT_USERNAME = "django_python3_ldap.utils.format_username_openldap"
LDAP_AUTH_ACTIVE_DIRECTORY_DOMAIN = None 
LDAP_AUTH_CONNECTION_USERNAME = "cn=Manager,dc=maxcrc,dc=com" 
LDAP_AUTH_CONNECTION_PASSWORD = "*****" 

LDAP_AUTH_CONNECT_TIMEOUT = None
LDAP_AUTH_RECEIVE_TIMEOUT = None

AUTHENTICATION_BACKENDS = (
    "django_python3_ldap.auth.LDAPBackend",
)

我的版本是 Python - 3.6.3(64 位) Django - 1.11.6(64位) Windows 10 - 64 位

谢谢

【问题讨论】:

    标签: python django authentication ldap


    【解决方案1】:

    django-auth-ldap 由于其依赖关系,需要编译。特别是在 Windows 上,我建议尝试纯 Python 解决方案。我使用的非常好用的是django-python3-ldap,你可以在这里找到:

    https://github.com/etianen/django-python3-ldap

    这是我设置设置的方式,这样我们也可以直接使用这些值与ldap3 连接:

    AUTHENTICATION_BACKENDS = [
        'django.contrib.auth.backends.ModelBackend',
        'django_python3_ldap.auth.LDAPBackend',
    ]
    
    # LDAP Connection Settings
    LDAP_AUTH_HOST = 'ldap.example.com'
    LDAP_AUTH_PORT = 636
    LDAP_AUTH_URL = 'ldaps://{host}:{port}'.format(
        host=LDAP_AUTH_HOST,
        port=LDAP_AUTH_PORT,
    )
    LDAP_AUTH_CONNECTION_USERNAME = 'ldapuser'
    LDAP_AUTH_CONNECTION_PASSWORD = 'ldappassword'
    
    # Initiate TLS on connection.
    LDAP_AUTH_USE_TLS = True
    
    # The LDAP search base for looking up users.
    LDAP_AUTH_SEARCH_BASE = "ou=People,dc=example,dc=com"
    
    # The LDAP class that represents a user.
    LDAP_AUTH_OBJECT_CLASS = "shadowAccount"
    
    # User model fields mapped to the LDAP
    # attributes that represent them.
    LDAP_AUTH_USER_FIELDS = {
        "username": "uid",
    }
    
    # A tuple of fields used to uniquely identify a user.
    LDAP_AUTH_USER_LOOKUP_FIELDS = ("username",)
    

    自述文件还包括有关 Active Directory 的说明(如果您要连接到该目录)。祝你好运!

    【讨论】:

    • 感谢您的回复。现在我在“django-python3-ldap”工作。我已将 setting.py 配置为他们的文档,我可以运行“python manage.py ldap_sync_users”命令将数据同步到我的数据库。但如果我试图通过我的 view.py 进行身份验证,它会返回“LDAP 连接失败:LDAPInvalidCredentialsResult - 49 - invalidCredentials - None - None - bindResponse - None”错误。
    • 您是在尝试连接到 Active Directory 还是 OpenLDAP?您知道您使用的是什么 LDAP 架构吗?听起来它正在连接,但您的配置设置需要调整才能正确验证。
    • 我正在使用 OpenLDAP,但不确定使用的架构。我在问题部分更新了配置设置详细信息。
    • 我们使用了shadowAccount。我已修改我的答案以包含此设置的示例配置。您可以连接到您的 OpenLDAP 服务器并使用 LDAPAdmin 之类的内容浏览您的架构:ldapadmin.org
    • 我已经解决了这个问题。谢谢 FlipperPA
    【解决方案2】:

    对于那些像我一样因为任何原因无法离开 django-auth-ldap 的人:我解决了从这里下载和安装 python-ldap 二进制轮的问题

    https://www.lfd.uci.edu/~gohlke/pythonlibs/#python-ldap

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-08
      • 1970-01-01
      相关资源
      最近更新 更多