我正在尝试创建一个自定义装饰器,它使用flask-jwt-extended
库中的verify_jwt_in_request()
。我的代码如下所示:
@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和装饰程序中的打印都返回了verify_jwt_in_request
和get_jwt_identity
的None
我的代码中是否缺少某些内容
verify_jwt_in_request
不返回任何内容。如果令牌解码链中的任何内容失败,它将引发适当的异常相关问题 更多 >
编程相关推荐