Skip to content

Instantly share code, notes, and snippets.

@zaghaghi
Last active April 6, 2020 12:33
Show Gist options
  • Save zaghaghi/ba5e38beaacf244ca659f6a18bcbe9f7 to your computer and use it in GitHub Desktop.
Save zaghaghi/ba5e38beaacf244ca659f6a18bcbe9f7 to your computer and use it in GitHub Desktop.
from flask import request, abort, Response
from functools import wraps
def _realy_check_role_is_ok(roles, methods):
# all conditions will be checked here.
return True
def check_role(roles, methods):
def inner_function(function):
@wraps(function)
def wrapper(*args, **kwargs):
if _realy_check_roles_is_ok(roles, methods):
return function(*args, **kwargs)
return Response('Unauthorized Access', 401) # or abort(401)
return wrapper
return inner_function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment