Add simple example

authlib
informatic 2018-04-07 10:41:20 +02:00
parent 0f997ab8fa
commit 2ed8d3e9f7
1 changed files with 27 additions and 0 deletions

27
example.py Normal file
View File

@ -0,0 +1,27 @@
from flask import Flask, request, url_for, Markup
from spaceauth import SpaceAuth, login_required, cap_required
app = Flask('spaceauth-example')
app.config['SECRET_KEY'] = 'testing'
app.config['SPACEAUTH_CONSUMER_KEY'] = 'testing'
app.config['SPACEAUTH_CONSUMER_SECRET'] = 'asdTasdfhwqweryrewegfdsfJIxkGc'
auth = SpaceAuth(app)
@app.route('/')
def index():
return Markup('Hey! <a href="%s">Login with spaceauth</a> / %r') % (
url_for('spaceauth.login'), spaceauth.current_user)
@app.route('/profile')
@login_required
def profile():
return Markup('Hey {}!').format(spaceauth.current_user)
@app.route('/staff')
@cap_required('staff')
def staff_only():
return 'This is staff-only zone!'
if __name__ == "__main__":
app.run()