Add global auth

This commit is contained in:
DingZQ
2025-06-22 23:14:34 +08:00
parent 5ab7246317
commit d53b5f0409

10
main.py
View File

@@ -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