-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.py
More file actions
20 lines (17 loc) · 741 Bytes
/
middleware.py
File metadata and controls
20 lines (17 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from flask import request, jsonify
from http import HTTPStatus
from utils import Utils
from flask_jwt_extended.exceptions import NoAuthorizationError
utils = Utils()
def check_token_expiry():
if request.path in ['/api/login', '/api/register', '/api/cron/task-reminder']:
return None
auth_header = request.headers.get('Authorization')
try:
if auth_header and auth_header.startswith('Bearer'):
token = auth_header.split()[1]
res = utils.verify_token(token=token)
if not res:
return jsonify({"error": "Expired token"}), HTTPStatus.UNAUTHORIZED
except NoAuthorizationError:
return jsonify({"error": "Expired token"}), HTTPStatus.UNAUTHORIZED