Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rustymyers/52c58d2c9c277eeb99a39972ec383eb2 to your computer and use it in GitHub Desktop.
Save rustymyers/52c58d2c9c277eeb99a39972ec383eb2 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# import ldap as l
from flask import Flask, g, request, session, redirect, url_for
from flask_simpleldap import LDAP
app = Flask(__name__)
app.secret_key = "welfhwdlhwdlfhwelfhwlehfwlehfelwehflwefwlehflwefhlwefhlewjfhwelfjhweflhweflhwel"
app.debug = True
# ldap config
app.config['LDAP_HOST'] = 'DOMAIN.EXAMPLE.COM'
# app.config['LDAP_REALM_NAME'] = 'DOMAIN.EXAMPLE.COM'
app.config['LDAP_BASE_DN'] = 'OU=Users,DC=DOMAIN,DC=EXAMPLE,DC=COM'
app.config['LDAP_USERNAME'] = 'user@DOMAIN.EXAMPLE.COM'
app.config['LDAP_PASSWORD'] = 'password'
app.config['LDAP_USE_TLS'] = True
app.config['LDAP_OPENLDAP'] = False
# domain & search base
app.config['LDAP_DOMAIN'] = 'DOMAIN.EXAMPLE.COM'
app.config['LDAP_REQUIRED_GROUP'] = ('OU=Users,DC=DOMAIN,DC=EXAMPLE,DC=COM')
ldap = LDAP(app)
@app.before_request
def before_request():
g.user = None
@app.route('/', methods = ['GET', 'POST'])
@ldap.basic_auth_required
def index():
return 'Welcome, {0}!'.format(g.ldap_username)
if __name__ == '__main__':
app.run(debug=True, port=8080, host="0.0.0.0")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment