Fix hallucination over FastAPI Basic auth
This commit is contained in:
parent
c86d4321ad
commit
4c8f121f58
6
main.py
6
main.py
@ -19,17 +19,17 @@ app = FastAPI()
|
||||
file_mapping = {}
|
||||
indexers = []
|
||||
|
||||
AUTH_SCHEME = HTTPBasic()
|
||||
security = HTTPBasic()
|
||||
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"""
|
||||
if expected_password is not None and credentials.password != expected_password:
|
||||
raise HTTPException(
|
||||
status_code=401,
|
||||
detail="Incorrect password",
|
||||
headers={"WWW-Authenticate": AUTH_SCHEME.getobfuscation_header()},
|
||||
headers={"WWW-Authenticate": "Basic"},
|
||||
)
|
||||
return credentials.username
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user