A simple Flask extension implementing Olin's authentication
Project description
Flask-OlinAuth implements OlinApps auth. It automatically provides a /olinauthlogin and /olinauthlogout route to the application, handling the process of actually authenticating a user with olinapps.
At a high level, Flask-OlinAuth provides two useful pieces for your application, both of which are demonstrated in example.py.
@auth_required
A simple function decorator which ensures that a user is logged in before a view is shown. The user is redirected to the login portal, with correct arguments, if not.
current_user
A nice local proxy for all of your views to get the current user, formatted as a dictionary.
logout_user
Will log out the currently authenticated user, allowing you to simply create your own logout view.
Flask-OlinAuth is very heavily inspired by Flask-Login, with structure, and functionality adopted, and much knowledge gained.
Installation
Install the extension with one of the following commands:
$ easy_install flask-olinauth
or alternatively if you have pip installed (which you should):
$ pip install flask-olinauth
Example Usage
from flask import Flask, url_for
from flask.ext.olinauth import OlinAuth, auth_required, current_user
app = Flask(__name__)
SECRET_KEY = "yeah, not actually a secret"
DEBUG = True
app.config.from_object(__name__)
oa = OlinAuth(app, 'localhost:5000')
#initial OlinAuth, with callback host of localhost:5000, for local server
oa.init_app(app, 'localhost:5000')
@app.route("/")
def index():
if current_user:
responseString = "Awesome index, guess what? %s is logged in. Sweet, right?" % current_user['id']
else:
responseString = "<html>It is kind of lonely here... No users are logged in. <a href=%s>Checkout my secret</a> </html>" % url_for('secret')
return responseString
@app.route("/secret")
@auth_required
def secret():
return "I wouldn't normally show you this, but since %s is logged in, here is the secret: 42" % current_user['id']
if __name__ == "__main__":
app.run(debug=True)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file Flask-OlinAuth-1.0.1.zip.
File metadata
- Download URL: Flask-OlinAuth-1.0.1.zip
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6b454b9cedcd2231ef4a2f37a54e1976598f219f3d9997fe8a27b1f488d545e
|
|
| MD5 |
580c3ecfe5dc99bf620c7bd65aa8b24c
|
|
| BLAKE2b-256 |
841d60c0c0bf4a745ae7c1c89b1a361fe16d497accd02f6b990eb519ca584056
|
File details
Details for the file Flask-OlinAuth-1.0.1.win32.exe.
File metadata
- Download URL: Flask-OlinAuth-1.0.1.win32.exe
- Upload date:
- Size: 203.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41decca287bc9db1b0ff8786041e79f4d118538830554f4ea2e74737a31808f7
|
|
| MD5 |
d2b0ebc92c0c817d7f860383caf18ae5
|
|
| BLAKE2b-256 |
f06c1baf2699c0731090d6db11538758e70c398a89c80e19bcf1e80393dff599
|