Implemented client nickname and access token
All checks were successful
release-image / release-image (push) Successful in 2m9s
All checks were successful
release-image / release-image (push) Successful in 2m9s
This commit is contained in:
@@ -6,6 +6,7 @@ from quart import Blueprint, jsonify, request, abort, current_app
|
||||
from werkzeug.exceptions import HTTPException
|
||||
from enum import Enum
|
||||
from internal.types import ActiveClient, NodeCommands, UserRoles
|
||||
from quart_jwt_extended import create_access_token
|
||||
from quart_jwt_extended import jwt_required
|
||||
from routers.auth import role_required
|
||||
|
||||
@@ -15,11 +16,16 @@ nodes_bp = Blueprint('nodes', __name__)
|
||||
pending_requests = {}
|
||||
|
||||
|
||||
async def register_client(websocket, client_id):
|
||||
async def register_client(websocket, client_id, nickname):
|
||||
"""Registers a new client connection."""
|
||||
current_app.active_clients[client_id] = ActiveClient(websocket)
|
||||
current_app.active_clients[client_id] = ActiveClient()
|
||||
current_app.active_clients[client_id].websocket = websocket
|
||||
current_app.active_clients[client_id].nickname = 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": nickname, "type": "node"})
|
||||
|
||||
# Start a task to listen for messages from this client
|
||||
asyncio.create_task(listen_to_client(websocket, client_id))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user