0

我正在尝试创建一个使用库的自定义装饰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 和装饰器中的打印结果都返回Noneverify_jwt_in_requestget_jwt_identity.

我的代码中是否缺少某些内容?

4

1 回答 1

1

verify_jwt_in_request不返回任何东西。如果令牌解码链中的任何内容失败,它将引发适当的异常。

于 2020-04-26T14:01:53.050 回答