Spaces:
No application file
No application file
from typing import Annotated | |
from fastapi import Depends, HTTPException, status | |
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer | |
from settings import settings | |
def verify_bearer( | |
http_auth: Annotated[ | |
HTTPAuthorizationCredentials | None, | |
Depends( | |
HTTPBearer( | |
description="Please provide AUTH_SECRET api key.", auto_error=False | |
) | |
), | |
], | |
) -> None: | |
if not settings.AUTH_SECRET: | |
return | |
auth_secret = settings.AUTH_SECRET.get_secret_value() | |
if not http_auth or http_auth.credentials != auth_secret: | |
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED) | |