Skip to content

Commit 0009633

Browse files
Andreas MollAndreas Moll
authored andcommitted
Improve logout method in blacklist example
1 parent 9fc12f6 commit 0009633

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

examples/blacklist.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,19 @@ def refresh():
5656
return jsonify(ret), 200
5757

5858

59-
# Endpoint for revoking a token when logging out
59+
# Endpoint for revoking an access token when logging out.
60+
# Please make sure JWT_BLACKLIST_TOKEN_CHECKS is set to 'all'
6061
@app.route('/logout', methods=['POST'])
6162
@jwt_required
6263
def logout():
6364
jwt = get_raw_jwt()
6465
jti = jwt['jti']
65-
revoke_token(jti)
66+
try:
67+
revoke_token(jti)
68+
except KeyError:
69+
return jsonify({
70+
'msg': 'Requires access tokens to be blacklisted'
71+
}), 500
6672
return jsonify({"msg": "Successfully logged out"}), 200
6773

6874

0 commit comments

Comments
 (0)