Coverage for docs_src / authentication_error_status_code / tutorial001_an_py310.py: 100%
11 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
1from typing import Annotated 1abc
3from fastapi import Depends, FastAPI, HTTPException, status 1abc
4from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer 1abc
6app = FastAPI() 1abc
9class HTTPBearer403(HTTPBearer): 1abc
10 def make_not_authenticated_error(self) -> HTTPException: 1abc
11 return HTTPException( 1def
12 status_code=status.HTTP_403_FORBIDDEN, detail="Not authenticated"
13 )
16CredentialsDep = Annotated[HTTPAuthorizationCredentials, Depends(HTTPBearer403())] 1abc
19@app.get("/me") 1abc
20def read_me(credentials: CredentialsDep): 1abc
21 return {"message": "You are authenticated", "token": credentials.credentials} 1ghi