我正在尝试创建一个使用库的自定义装饰verify_jwt_in_request()
器flask-jwt-extended
。我的代码如下所示:
@app.route("/test-auth", methods=["POST"])
@custom_auth_required
def test_auth():
print(verify_jwt_in_request())
print(get_jwt_identity())
return Response(json.dumps({"test": "test"}), status=HTTP_200_OK,
mimetype='application/json')
def custom_auth_required(f):
@wraps(f)
def decorated(*args, **kwargs):
params = request.json
headers = request.headers
print(verify_jwt_in_request())
print(get_jwt_identity())
try:
if verify_jwt_in_request():
print("validated")
else:
print("invalid")
return f(*args, **kwargs)
except KeyError:
raise AuthError({"code": "something","description": "something else"}, 401)
return decorated
出于某种原因,我在 API 和装饰器中的打印结果都返回None
了verify_jwt_in_request
和get_jwt_identity
.
我的代码中是否缺少某些内容?