Django用户认证:django

系统教程 行业动态 更新时间:2024-06-14 16:59:22
Django用户认证:django_auth_ldap.backend.LDAPBackend(Django user authentication: django_auth_ldap.backend.LDAPBackend)

我不明白如何在django中使用LDAPBackend,我只想通过LDAP来验证用户身份。 我已经尝试了以下内容:

from django_auth_ldap.backend import LDAPBackend auth = LDAPBackend() user = auth.authenticate(username='my_uid',password='pwd')

此时用户是None,看着tcpdump我看不到任何到LDAP服务器的连接尝试。

settings.py AUTH_LDAP_SERVER_URI = 'ldap.example.com' AUTH_LDAP_USER_DN_TEMPLATE = 'uid=%(user)s,ou=People,dc=example,dc=com' AUTH_LDAP_BIND_AS_AUTHENTICATING_USER = True AUTH_LDAP_CACHE_GROUPS = True AUTH_LDAP_GROUP_CACHE_TIMEOUT = 3600 AUTH_LDAP_USER_ATTR_MAP = { "first_name": "givenName", "last_name": "sn", "email": "mail" } AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend', 'django_auth_ldap.backend.LDAPBackend', )

官方的django文档没有提供关于如何在视图中使用该后端的任何片段。

非常感谢您的帮助!

I don't understand how to use the LDAPBackend in django, all I want to do is to authenticate a user against LDAP. I have tried the following:

from django_auth_ldap.backend import LDAPBackend auth = LDAPBackend() user = auth.authenticate(username='my_uid',password='pwd')

At this point user is None and looking at tcpdump I can't see any connection attempt to the LDAP server.

settings.py AUTH_LDAP_SERVER_URI = 'ldap.example.com' AUTH_LDAP_USER_DN_TEMPLATE = 'uid=%(user)s,ou=People,dc=example,dc=com' AUTH_LDAP_BIND_AS_AUTHENTICATING_USER = True AUTH_LDAP_CACHE_GROUPS = True AUTH_LDAP_GROUP_CACHE_TIMEOUT = 3600 AUTH_LDAP_USER_ATTR_MAP = { "first_name": "givenName", "last_name": "sn", "email": "mail" } AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend', 'django_auth_ldap.backend.LDAPBackend', )

The official django doc doesn't provide any snippet about how to use this backend in a view.

Many thanks for your help!

最满意答案

所有django-auth-ldap的文档都在这里 。 为了调试你的配置,你需要在'django_auth_ldap'记录器上安装日志处理程序; 有关更多信息,请参阅Django的日志记录文档 。

乍一看,我想说的一个问题是AUTH_LDAP_SERVER_URI没有设置为URI; 尝试一下形式ldap://ldap.example.com/ 。 您还需要查看AUTH_LDAP_BIND_AS_AUTHENTICATING_USER的文档:这是一种高级且有点微妙的选项,只有在您知道需要时才应启用。

All of the documentation for django-auth-ldap is here. For debugging your configuration, you'll want to install a logging handler on the 'django_auth_ldap' logger; see Django's logging documentation for more on that.

At a glance, I would say that one problem is that AUTH_LDAP_SERVER_URI is not set to a URI; try something of the form ldap://ldap.example.com/. You'll also want to review the documentation for AUTH_LDAP_BIND_AS_AUTHENTICATING_USER: this is an advanced and somewhat subtle option that you should only enable if you know that you need it.

更多推荐

本文发布于:2023-04-16 19:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/8a9cb9be15dc581a570fb6381a3ebbe0.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:用户   Django   django

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!