Support auth for szh branch
This commit is contained in:
15
main.py
15
main.py
@@ -31,6 +31,8 @@ import logging
|
||||
import threading
|
||||
import time
|
||||
from logging.handlers import TimedRotatingFileHandler
|
||||
from fastapi import FastAPI, APIRouter, Depends, HTTPException, status, Request
|
||||
from fastapi.security import OAuth2PasswordBearer
|
||||
|
||||
JUNCTION = 0
|
||||
RESERVOIR = 1
|
||||
@@ -51,6 +53,19 @@ if not os.path.exists(inpDir):
|
||||
if not os.path.exists(tmpDir):
|
||||
os.mkdir(tmpDir)
|
||||
|
||||
# 全局依赖项
|
||||
async def global_auth(request: Request):
|
||||
# 白名单跳过
|
||||
# if request.url.path in WHITE_LIST:
|
||||
# return
|
||||
# 验证
|
||||
token = request.headers.get("Authorization")
|
||||
if token != "expected_token":
|
||||
raise HTTPException(status_code=401, detail="Invalid token")
|
||||
|
||||
# 全局依赖项
|
||||
# app = FastAPI(dependencies=[Depends(global_auth)])
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
# 将 Query的信息 序列号到 redis/json, 默认不支持datetime,需要自定义
|
||||
|
||||
Reference in New Issue
Block a user