From d53b5f0409d7b557b63e71854b02723f124ec7e9 Mon Sep 17 00:00:00 2001 From: DingZQ Date: Sun, 22 Jun 2025 23:14:34 +0800 Subject: [PATCH] Add global auth --- main.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index f40261f..fb844d9 100644 --- a/main.py +++ b/main.py @@ -60,13 +60,13 @@ async def global_auth(request: Request): # return # 验证 token = request.headers.get("Authorization") - if token != "expected_token": + if token != "567e33c876a2": raise HTTPException(status_code=401, detail="Invalid token") # 全局依赖项 -# app = FastAPI(dependencies=[Depends(global_auth)]) +app = FastAPI(dependencies=[Depends(global_auth)]) -app = FastAPI() +# app = FastAPI() access_tokens = [] @@ -1772,9 +1772,7 @@ async def fastapi_get_node_coord(network: str, node: str) -> dict[str, float] | # node type: junction, reservoir, tank # link type: pipe, pump, valve @app.get("/getnetworkgeometries/") -async def fastapi_get_network_geometries(network: str, token: str) -> dict[str, Any] | None: - if token != "567e33c876a2": - raise HTTPException(status_code=401, detail="Unauthorized") +async def fastapi_get_network_geometries(network: str) -> dict[str, Any] | None: # 获取所有节点坐标# 缓存查询结果提高性能 global redis_client