lordlabakdas
lordlabakdas

Reputation: 1193

verify_jwt_in_request() returns None when called in custom Flask Decorator

I am trying to create a custom decorator that makes use of verify_jwt_in_request() from the flask-jwt-extended library. My code is laid out as below:

@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

For some reason my prints in both the API and the decorator return None for both verify_jwt_in_request and get_jwt_identity.

Is there something am missing in my code?

Upvotes: 0

Views: 3121

Answers (1)

vimalloc
vimalloc

Reputation: 4167

verify_jwt_in_request does not return anything. It will raise an appropriate exception if anything in the token decoding chain fails.

Upvotes: 1

Related Questions