Implement access token
This commit is contained in:
@@ -20,6 +20,9 @@ CLIENT_API_URL = os.getenv("CLIENT_API_URL", "http://localhost:8001")
|
||||
if not app_conf.get("client_id"):
|
||||
app_conf.set("client_id", f"client-{uuid.uuid4().hex[:8]}")
|
||||
CLIENT_ID = app_conf.client_id
|
||||
|
||||
# Get the nickname (even if it's empty)
|
||||
NICKNAME = app_conf.get("nickname")
|
||||
# ----------------------------
|
||||
|
||||
# Dictionary mapping command names (strings) to local client functions
|
||||
@@ -222,6 +225,9 @@ async def receive_commands(websocket):
|
||||
else:
|
||||
print(f"Received unknown command: {command_name}")
|
||||
elif data.get("type") == "handshake_ack":
|
||||
# Set the session token
|
||||
app_conf.set(data.get("access_token"))
|
||||
|
||||
print(f"Server acknowledged handshake.")
|
||||
else:
|
||||
print(f"Received unknown message type: {data.get('type')}")
|
||||
@@ -242,7 +248,7 @@ async def main_client():
|
||||
print("Connection established.")
|
||||
|
||||
# Handshake: Send client ID immediately after connecting
|
||||
handshake_message = json.dumps({"type": "handshake", "id": CLIENT_ID})
|
||||
handshake_message = json.dumps({"type": "handshake", "id": CLIENT_ID, "nickname": NICKNAME})
|
||||
await websocket.send(handshake_message)
|
||||
print(f"Sent handshake with ID: {CLIENT_ID}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user