Skip to content

Commit f87cbf5

Browse files
committed
Added revoked and invalid token callbacks
1 parent 4e649ca commit f87cbf5

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

backend/PyMatcha/__init__.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,25 @@ def check_if_token_is_revoked(decrypted_token):
257257
application.register_blueprint(debug_bp)
258258

259259

260+
@jwt.revoked_token_loader
261+
def jwt_revoked_token_callback():
262+
return (
263+
jsonify(
264+
{
265+
"code": 401,
266+
"error": {
267+
"message": "Token has been revoked.",
268+
"name": "Unauthorized Error",
269+
"solution": "Please login again",
270+
"type": "UnauthorizedError",
271+
},
272+
"success": False,
273+
}
274+
),
275+
401,
276+
)
277+
278+
260279
@jwt.unauthorized_loader
261280
def no_jwt_callback(error_message):
262281
return (
@@ -276,6 +295,25 @@ def no_jwt_callback(error_message):
276295
)
277296

278297

298+
@jwt.invalid_token_loader
299+
def jwt_invalid_token_callback(error_message):
300+
return (
301+
jsonify(
302+
{
303+
"code": 400,
304+
"error": {
305+
"message": error_message,
306+
"name": "Bad Request Error",
307+
"solution": "Try again (The token is invalid)",
308+
"type": "BadRequestError",
309+
},
310+
"success": False,
311+
}
312+
),
313+
400,
314+
)
315+
316+
279317
# import tasks here to be registered by celery
280318

281319
import PyMatcha.utils.tasks # noqa

0 commit comments

Comments
 (0)