Proper use of Flask-ldap

Nvasion picture Nvasion · Jul 25, 2014 · Viewed 7.6k times · Source

I am currently trying to use Flask-LDAP for authentication purposes for Sandman. Unlike normal python LDAP where the documentation is pretty straight forward, this is pretty offbase.

Example from documentation.

from flask import Flask
from flask.ext.ldap import LDAP, login_required
from flask.ext.pymongo import PyMongo
app = Flask(__name__)
app.debug = True

app.config['LDAP_HOST'] = 'ldap.example.com'
app.config['LDAP_DOMAIN'] = 'example.com'
app.config['LDAP_SEARCH_BASE'] = 'OU=Domain Users,DC=example,DC=com'
app.config['LDAP_LOGIN_VIEW'] = 'custom_login'

app.config['MONGO_DBNAME'] = 'simpledb'
mongo = PyMongo(app, config_prefix='MONGO')
ldap = LDAP(app, mongo)
app.secret_key = "welfhwdlhwdlfhwelfhwlehfwlehfelwehflwefwlehflwefhlwefhlewjfhwelfjhweflhweflhwel"
app.add_url_rule('/login', 'login', ldap.login, methods=['GET', 'POST'])

This does not tell me where I can place my dn or password. So I am completely confused as to how this thing actually works.

Has anyone effectively used Flask-LDAP and if so how did you set it up? Or is there a better product out there like flask-login that I should use?

Thanks,

Answer

Csaba Szilveszter picture Csaba Szilveszter · Sep 23, 2014

Flask-login is okay and the de-facto lib for session management so you'll be needing that.

As for flask-ldap, yeah it's not well documented...

But this might be useful to you (it seems like a full feature ldap lib for flask including login helpers): flask_ldap_login at https://github.com/ContinuumIO/flask-ldap-login