From dfadbe61ae26fd5d89fdcc599277e3df1d573b07 Mon Sep 17 00:00:00 2001
From: Timothy Allen <Timothy.Allen@optiver.com.au>
Date: Wed, 19 Nov 2014 12:17:55 +1100
Subject: [PATCH] Add an example of using .basic_auth_required()

---
 examples/basic_auth/app.py | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
 create mode 100644 examples/basic_auth/app.py

diff --git a/examples/basic_auth/app.py b/examples/basic_auth/app.py
new file mode 100644
index 0000000..e8905bd
--- /dev/null
+++ b/examples/basic_auth/app.py
@@ -0,0 +1,21 @@
+from flask import Flask, g, request, session, redirect, url_for
+from flask.ext.simpleldap import LDAP
+
+app = Flask(__name__)
+app.secret_key = 'dev key'
+app.debug = True
+
+app.config['LDAP_HOST'] = 'ldap.example.org'
+app.config['LDAP_BASE_DN'] = 'OU=users,dc=example,dc=org'
+app.config['LDAP_USERNAME'] = 'CN=user,OU=Users,DC=example,DC=org'
+app.config['LDAP_PASSWORD'] = 'password'
+
+ldap = LDAP(app)
+
+@app.route('/')
+@ldap.basic_auth_required
+def index():
+    return "Welcome, {0}!".format(g.ldap_username)
+
+if __name__ == '__main__':
+    app.run()
-- 
GitLab