def check_jwt_authorization():
current_identity = getattr(_request_ctx_stack.top,
'current_identity', None)
if current_identity:
return current_identity
skip_check = False
if current_app.config.get("disable_jwt", False):
skip_check = True
if request.endpoint in current_app.view_functions:
fn = current_app.view_functions[request.endpoint]
# Check Flask-RESTful endpoints for openness
if hasattr(fn, "view_class"):
exempt = getattr(fn.view_class, "no_jwt_check", [])
if request.method in exempt:
skip_check = True
elif fn in _open_endpoints:
skip_check = True
# the static folder is open to all without authentication
if request.endpoint == "static" or request.url.endswith("favicon.ico"):
skip_check = True
# In case the endpoint requires no authorization, and the request does not
# carry any authorization info as well, we will not try to verify any JWT's
if skip_check and 'Authorization' not in request.headers:
return
token, auth_type = get_auth_token_and_type()
current_identity = verify_token(token, auth_type)
if auth_type == "JWT":
# Cache this token
cache_token(current_identity)
# Authorization token has now been converted to a verified payload
_request_ctx_stack.top.current_identity = current_identity
return current_identity
评论列表
文章目录