Fix hallucination over FastAPI Basic auth

This commit is contained in:
Timothy Farrell 2026-04-12 17:25:35 +00:00
parent c86d4321ad
commit 4c8f121f58

View File

@ -19,17 +19,17 @@ app = FastAPI()
file_mapping = {} file_mapping = {}
indexers = [] indexers = []
AUTH_SCHEME = HTTPBasic() security = HTTPBasic()
expected_password: str | None = None expected_password: str | None = None
async def get_current_username(credentials: HTTPBasicCredentials = Depends(AUTH_SCHEME)) -> str: async def get_current_username(credentials: Annotated[HTTPBasicCredentials, Depends(security)]) -> str:
"""Verify Basic Authentication credentials""" """Verify Basic Authentication credentials"""
if expected_password is not None and credentials.password != expected_password: if expected_password is not None and credentials.password != expected_password:
raise HTTPException( raise HTTPException(
status_code=401, status_code=401,
detail="Incorrect password", detail="Incorrect password",
headers={"WWW-Authenticate": AUTH_SCHEME.getobfuscation_header()}, headers={"WWW-Authenticate": "Basic"},
) )
return credentials.username return credentials.username