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"] = "ad.mydomain.com"

# Base DN of your directory
app.config["LDAP_BASE_DN"] = "dc=mydomain,dc=com"

# Users DN to be prepended to the Base DN
app.config["LDAP_USER_DN"] = "ou=users"

# Groups DN to be prepended to the Base DN
app.config["LDAP_GROUP_DN"] = "ou=groups"

# 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"] = "mail"

# The Username to bind to LDAP with
app.config["LDAP_BIND_USER_DN"] = None

# The Password to bind to LDAP with
app.config["LDAP_BIND_USER_PASSWORD"] = None
Example #2
0
from flask import Flask, url_for
from flask_ldap3_login import LDAP3LoginManager
from flask_login import LoginManager, login_user, UserMixin, current_user
from flask import render_template_string, redirect
from flask.ext.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.
app.config["LDAP_HOST"] = "ad.mydomain.com"  # Hostname of your LDAP Server
app.config["LDAP_BASE_DN"] = "dc=mydomain,dc=com"  # Base DN of your directory
app.config["LDAP_USER_DN"] = "ou=users"  # Users DN to be prepended to the Base DN
app.config["LDAP_GROUP_DN"] = "ou=groups"  # Groups DN to be prepended to the Base DN

app.config["LDAP_USER_RDN_ATTR"] = "cn"  # The RDN attribute for your user schema on LDAP
app.config["LDAP_USER_LOGIN_ATTR"] = "mail"  # The Attribute you want users to authenticate to LDAP with.
app.config["LDAP_BIND_USER_DN"] = None  # The Username to bind to LDAP with
app.config["LDAP_BIND_USER_PASSWORD"] = None  # The Password to bind to LDAP with

login_manager = LoginManager(app)  # Setup a Flask-Login Manager
ldap_manager = LDAP3LoginManager(app)  # Setup a LDAP3 Login Manager.

# Create a dictionary to store the users in when they authenticate
# This example stores users in memory.
users = {}


# Declare an Object Model for the user, and make it comply with the