Created
May 5, 2017 18:01
-
-
Save rustymyers/52c58d2c9c277eeb99a39972ec383eb2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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