From f41ca9e5dc78baa5a50c32ed05c05876266c6dd4 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期六, 12 十月 2024 14:24:18 +0800
Subject: [PATCH] 对话的token从url传

---
 app/api/__init__.py |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/app/api/__init__.py b/app/api/__init__.py
index 5ddd5aa..51c31da 100644
--- a/app/api/__init__.py
+++ b/app/api/__init__.py
@@ -48,11 +48,10 @@
 
 
 async def get_current_user_websocket(websocket: WebSocket):
-    auth_header = websocket.headers.get('Authorization')
-    if auth_header is None or not auth_header.startswith('Bearer '):
+    token = websocket.query_params.get('token')
+    if token is None:
         await websocket.close(code=1008)
         raise WebSocketDisconnect(code=status.WS_1008_POLICY_VIOLATION)
-    token = auth_header[len('Bearer '):]
     try:
         payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
         username: str = payload.get("sub")
@@ -67,4 +66,4 @@
     except jwt.PyJWTError as e:
         print(e)
         await websocket.close(code=1008)
-        raise WebSocketDisconnect(code=status.WS_1008_POLICY_VIOLATION)
+        raise WebSocketDisconnect(code=status.WS_1008_POLICY_VIOLATION)
\ No newline at end of file

--
Gitblit v1.8.0