首页 > 解决方案 > 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)

标签: pythonldapflask-login

解决方案


推荐阅读