Skip to content

Instantly share code, notes, and snippets.

@mike1e mike1e/flask_auth.py
Last active Jan 3, 2016

Embed
What would you like to do?
Flask authorization
def login_required(role="ANY"):
def wrapper(fn):
@wraps(fn)
def decorated_view(*args, **kwargs):
if not current_user.is_authenticated():
return current_app.login_manager.unauthorized()
urole = current_user.get_role()
if ( (urole != role) and (role != "ANY")):
logout_user()
return current_app.login_manager.unauthorized()
return fn(*args, **kwargs)
return decorated_view
return wrapper
@app.route('/school/')
@login_required(role="SCHOOL")
def restricted_view_for_school():
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.