我正在尝试创建一个自定义装饰器,它使用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
。
我的代码中有没有遗漏什么?
发布于 2020-04-26 22:01:53
verify_jwt_in_request
不返回任何内容。如果令牌解码链中的任何内容失败,它将引发适当的异常。
https://stackoverflow.com/questions/61399460
复制相似问题