crawler_task_management/public_function/auth.py

15 lines
450 B
Python

from fastapi import Request
from fastapi.responses import JSONResponse
TOKEN = "opB4ztbdw45xFoJbXti20520bsEq3UDKKAtiDWHnGjjhP6v0KNFjqBM7bfzto6GLdUPviYnVdCgdCJYqe42nPoy6mvW59F3TPQZu"
async def verify_tk_token(request: Request, call_next):
"""鉴权中间件"""
token = request.headers.get("token")
if token != TOKEN:
return JSONResponse(status_code=401, content={"detail": "Unauthorized"})
return await call_next(request)