diff --git a/examples/authorized_sanic.py b/examples/authorized_sanic.py index f6b17426..7b5b7501 100644 --- a/examples/authorized_sanic.py +++ b/examples/authorized_sanic.py @@ -13,28 +13,26 @@ def check_request_for_authorization_status(request): return flag -def authorized(): - def decorator(f): - @wraps(f) - async def decorated_function(request, *args, **kwargs): - # run some method that checks the request - # for the client's authorization status - is_authorized = check_request_for_authorization_status(request) +def authorized(f): + @wraps(f) + async def decorated_function(request, *args, **kwargs): + # run some method that checks the request + # for the client's authorization status + is_authorized = check_request_for_authorization_status(request) - if is_authorized: - # the user is authorized. - # run the handler method and return the response - response = await f(request, *args, **kwargs) - return response - else: - # the user is not authorized. - return json({'status': 'not_authorized'}, 403) - return decorated_function - return decorator + if is_authorized: + # the user is authorized. + # run the handler method and return the response + response = await f(request, *args, **kwargs) + return response + else: + # the user is not authorized. + return json({'status': 'not_authorized'}, 403) + return decorated_function @app.route("/") -@authorized() +@authorized async def test(request): return json({'status': 'authorized'})