From 7820e87989b5364a5fb3c6b4ad7f9393b197d03f Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Sun, 29 Jun 2025 01:43:09 -0400 Subject: [PATCH] Update JWT to not expire for nodes and expire in 1 hour for users --- app/routers/auth.py | 3 ++- app/routers/nodes.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/routers/auth.py b/app/routers/auth.py index a37637e..5077ce3 100644 --- a/app/routers/auth.py +++ b/app/routers/auth.py @@ -5,6 +5,7 @@ from quart_jwt_extended import create_access_token, jwt_required, get_jwt_identi from internal.auth_wrappers import UserDbController from internal.types import UserRoles from uuid import uuid4 +from datetime import timedelta # Import the centralized JWTManager instance from config.jwt_config import jwt as jwt_manager_instance # Renamed to avoid confusion with jwt_required @@ -97,7 +98,7 @@ async def login_user(): if not user or not check_password_hash(user.password_hash, password): abort(401, "Invalid credentials") - access_token = create_access_token(identity={"id": user._id, "username": user.username, "type": "user"}) + access_token = create_access_token(identity={"id": user._id, "username": user.username, "type": "user"}, expires_delta=timedelta(hours=1)) return jsonify({"access_token": access_token, "role": user.role, "username": user.username, "user_id": user._id }), 200 # DEPRECATED diff --git a/app/routers/nodes.py b/app/routers/nodes.py index e9326a0..edd20e6 100644 --- a/app/routers/nodes.py +++ b/app/routers/nodes.py @@ -24,7 +24,7 @@ async def register_client(websocket, client_id, client_nickname): print(f"Client {client_id} connected.") # Create a JWT for the client - current_app.active_clients[client_id].access_token = create_access_token(identity={"id": client_id, "username": client_nickname, "type": "node"}) + current_app.active_clients[client_id].access_token = create_access_token(identity={"id": client_id, "username": client_nickname, "type": "node"}, expires_delta=False) print(current_app.active_clients[client_id])