Select Git revision
app_oldap.py
-
Nickolay Ponomarev authored
As noted in: https://github.com/admiralobvious/flask-simpleldap/issues/5 https://github.com/admiralobvious/flask-simpleldap/issues/43 - @login_required can't be used without like that, so it makes sense to replace it with the more basic `@basic_auth_required`. - It's easy to forget to configure `LDAP_HOST`, and many people probably are trying to connect to a pre-existing directory, instead of bringing up their own.
Nickolay Ponomarev authoredAs noted in: https://github.com/admiralobvious/flask-simpleldap/issues/5 https://github.com/admiralobvious/flask-simpleldap/issues/43 - @login_required can't be used without like that, so it makes sense to replace it with the more basic `@basic_auth_required`. - It's easy to forget to configure `LDAP_HOST`, and many people probably are trying to connect to a pre-existing directory, instead of bringing up their own.
app_oldap.py 1023 B
from flask import Flask, g
from flask_simpleldap import LDAP
app = Flask(__name__)
# Base
app.config['LDAP_REALM_NAME'] = 'OpenLDAP Authentication'
app.config['LDAP_HOST'] = 'openldap.example.org'
app.config['LDAP_BASE_DN'] = 'dc=users,dc=openldap,dc=org'
app.config['LDAP_USERNAME'] = 'cn=user,ou=servauth-users,dc=users,dc=openldap,dc=org'
app.config['LDAP_PASSWORD'] = 'password'
# OpenLDAP
app.config['LDAP_OPENLDAP'] = True
app.config['LDAP_OBJECTS_DN'] = 'dn'
app.config['LDAP_USER_OBJECT_FILTER'] = '(&(objectclass=inetOrgPerson)(uid=%s))'
# Groups
app.config['LDAP_GROUP_MEMBERS_FIELD'] = "uniquemember"
app.config['LDAP_GROUP_OBJECT_FILTER'] = "(&(objectclass=groupOfUniqueNames)(cn=%s))"
app.config['LDAP_GROUP_MEMBER_FILTER'] = "(&(cn=*)(objectclass=groupOfUniqueNames)(uniquemember=%s))"
app.config['LDAP_GROUP_MEMBER_FILTER_FIELD'] = "cn"
ldap = LDAP(app)
@app.route('/')
@ldap.basic_auth_required
def index():
return 'Welcome, {0}!'.format(g.ldap_username)
if __name__ == '__main__':
app.run()