kilag
kilag

Reputation: 576

Flask JWT : @jwt.token_in_blacklist_loader is never call

I am building an application using flask-jet-extended, and I am on the part of logout from https://flask-jwt-extended.readthedocs.io/en/stable/blocklist_and_token_revoking/

My issue is that the decorator @jwt.token_in_blacklist_loader seems not working. I am doing that :

@bp.route('/logout', methods=('GET', 'POST'))
@jwt_required
def logout():
    jti = get_raw_jwt()["jti"]
    insert_jti_in_blacklist(jti) # function that insert jti in my database
    return redirect(url_for('auth.login')) #redirect to login


@jwt.token_in_blacklist_loader
def check_if_token_revoked(jwt_header, jwt_payload):$
    print("check revoked token")
    jti = jwt_payload["jti"]
    return jti_in_blacklist(jti) #function return True if my jti is in blacklist

and my function to test blacklist :

@bp.route('/account', methods=('GET', 'POST'))
@jwt_required
def account() -> str:
    print(jti_in_blacklist(get_raw_jwt()["jti"]))

what I am doing, is logout from my application, and then go to account the function print in account return "True" as expected (my token is in blacklist) but I never enter into check_if_token_revoked (I don't have I console the print "check revoked token)

So why it is not called? normally it is exactly the goal of this decorator, I don't understand why it is not working

Thanks

Upvotes: 0

Views: 748

Answers (2)

kilag
kilag

Reputation: 576

Thanks to @igor, I find in doc that I am on old version of jwt-extended where JWT_BLACKLIST_ENABLED is needed to put at "True"

now it is working properly with that

Upvotes: 1

Igor R. Braga
Igor R. Braga

Reputation: 121

Try change the @jwt_required to @jwt_required(), explanation here.

Upvotes: 0

Related Questions