CoolFace
Apppublic

wqngxiwn/database

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
auth.py14 linesDownload Raw Back to root
1from fastapi import HTTPException, Request2 3# 密码验证依赖4async def verify_password(request: Request, PASSWORD: str = None):5    """验证请求中的Bearer令牌是否与配置的密码匹配"""6    if PASSWORD:7        auth_header = request.headers.get("Authorization")8        if not auth_header or not auth_header.startswith("Bearer "):9            raise HTTPException(10                status_code=401, detail="Unauthorized: Missing or invalid token")11        token = auth_header.split(" ")[1]12        if token != PASSWORD:13            raise HTTPException(14                status_code=401, detail="Unauthorized: Invalid token")