From 9194ffa6b7feaf6d178de818f583ef65e2aafe61 Mon Sep 17 00:00:00 2001 From: Chingfeng Li Date: Mon, 20 Oct 2025 11:57:18 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A6=82=E6=9E=9C=E5=B7=B2=E7=BB=8F?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=BA=86auth=5Fkey=EF=BC=8C=E5=88=99?= =?UTF-8?q?=E4=B8=8D=E4=BD=BF=E7=94=A8uuid=E7=94=9F=E6=88=90=EF=BC=9B=20?= =?UTF-8?q?=E9=80=82=E9=85=8D=E5=8D=95=E6=A8=A1=E5=9D=97=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=EF=BC=8C=E9=98=B2=E6=AD=A2=E6=AF=8F=E6=AC=A1=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E9=87=8D=E5=90=AF=E8=AE=BE=E5=A4=87=E9=83=BD=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/app.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main/xiaozhi-server/app.py b/main/xiaozhi-server/app.py index 0edb475b..48ca8c9c 100644 --- a/main/xiaozhi-server/app.py +++ b/main/xiaozhi-server/app.py @@ -51,8 +51,9 @@ async def main(): # auth_key用于jwt认证,比如视觉分析接口的jwt认证 auth_key = config.get("manager-api", {}).get("secret", "") if not auth_key or len(auth_key) == 0 or "你" in auth_key: - auth_key = str(uuid.uuid4().hex) - config["server"]["auth_key"] = auth_key + if not config["server"]["auth_key"]: + auth_key = str(uuid.uuid4().hex) + config["server"]["auth_key"] = auth_key # 添加 stdin 监控任务 stdin_task = asyncio.create_task(monitor_stdin()) From ff048797a1ab8bbae791cbad4c7252e01387596b Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Mon, 20 Oct 2025 21:25:37 +0800 Subject: [PATCH 2/2] =?UTF-8?q?auth=5Fkey=E4=BC=98=E5=85=88=E7=BA=A7?= =?UTF-8?q?=EF=BC=9A=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6server.auth=5Fkey?= =?UTF-8?q?=20>=20manager-api.secret=20>=20=E8=87=AA=E5=8A=A8=E7=94=9F?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/xiaozhi-server/app.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/main/xiaozhi-server/app.py b/main/xiaozhi-server/app.py index 48ca8c9c..bc6f0b54 100644 --- a/main/xiaozhi-server/app.py +++ b/main/xiaozhi-server/app.py @@ -46,14 +46,19 @@ async def main(): check_ffmpeg_installed() config = load_config() - # 默认使用manager-api的secret作为auth_key - # 如果secret为空,则生成随机密钥 - # auth_key用于jwt认证,比如视觉分析接口的jwt认证 - auth_key = config.get("manager-api", {}).get("secret", "") + # auth_key优先级:配置文件server.auth_key > manager-api.secret > 自动生成 + # auth_key用于jwt认证,比如视觉分析接口的jwt认证、ota接口的token生成与websocket认证 + # 获取配置文件中的auth_key + auth_key = config["server"].get("auth_key", "") + + # 验证auth_key,无效则尝试使用manager-api.secret if not auth_key or len(auth_key) == 0 or "你" in auth_key: - if not config["server"]["auth_key"]: + auth_key = config.get("manager-api", {}).get("secret", "") + # 验证secret,无效则生成随机密钥 + if not auth_key or len(auth_key) == 0 or "你" in auth_key: auth_key = str(uuid.uuid4().hex) - config["server"]["auth_key"] = auth_key + + config["server"]["auth_key"] = auth_key # 添加 stdin 监控任务 stdin_task = asyncio.create_task(monitor_stdin())