python - Flask ldap3 登录问题
问题描述
当我尝试使用烧瓶 LDAP 连接到 AD 时,用于用户登录验证。我收到以下错误:有人遇到过以下错误吗?,如果有人可以提供帮助,那就太好了!
错误消息:SASLprep 错误:ASCII 控制字符存在 AuthenticationResponseStatus.fail
下面是代码
# importing Flask and other modules
from flask import Flask, url_for
from flask_ldap3_login import LDAP3LoginManager,AuthenticationResponseStatus
from flask_login import LoginManager, login_user, UserMixin, current_user
from flask import render_template_string, redirect
from flask_ldap3_login.forms import LDAPLoginForm
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret'
app.config['DEBUG'] = True
# Setup LDAP Configuration Variables. Change these to your own settings.
# All configuration directives can be found in the documentation.
# Hostname of your LDAP Server
app.config['LDAP_HOST'] = 'LDAP server name'
app.config['LDAP_USER_SEARCH_SCOPE'] = 'SUBTREE'
# Base DN of your directory
app.config['LDAP_BASE_DN'] = 'DC=example,DC=com'
# Users DN to be prepended to the Base DN
app.config['LDAP_USER_DN'] = 'ou=users'
app.config['LDAP_ALWAYS_SEARCH_BIND'] = 1
# The RDN attribute for your user schema on LDAP
app.config['LDAP_USER_RDN_ATTR'] = 'cn'
# The Attribute you want users to authenticate to LDAP with.
app.config['LDAP_USER_LOGIN_ATTR'] = 'sAMAccountName'
# The Username to bind to LDAP with
app.config['LDAP_BIND_USER_DN'] = 'CN= Service account name,OU=,DC=example,DC=com'
# The Password to bind to LDAP with
app.config['LDAP_BIND_USER_PASSWORD'] = "Password"
login_manager = LoginManager(app) # Setup a Flask-Login Manager
ldap_manager = LDAP3LoginManager(app) # Setup a LDAP3 Login Manager.
@app.route('/manual_login')
def manual_login():
result = app.ldap3_login_manager.authenticate("username", "password")
print(result.status)
return 'fail' if result.status == AuthenticationResponseStatus.fail else 'success'
if __name__ == "__main__":
app.run(debug=True)
解决方案
推荐阅读
- json - 是否有任何方法可以使 CreateML 训练模型保持最新?
- parsing - 使用全局变量和返回值的两个解析实现之间的时间复杂度差异
- android - Firebase 离线支持
- pandas - 提取熊猫数据框中的列时如何有效地设置缺失列的默认值
- swift - 如何调试具有网络扩展作为隧道提供程序的 macOS 应用程序的问题?
- r - ggnet 网络避免重叠标签
- javascript - 将旧聊天消息添加到聊天框
- discord.py - 如何添加编辑消息的频道?
- android - 西班牙语 Kotlin 语音识别
- javascript - 神话身份验证登录中的 ErrorException