Coverage for docs_src/authentication_error_status_code/tutorial001_an.py: 100%
11 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-04 08:29 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-04 08:29 +0000
1from fastapi import Depends, FastAPI, HTTPException, status 1abcdefg
2from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer 1abcdefg
3from typing_extensions import Annotated 1abcdefg
5app = FastAPI() 1abcdefg
8class HTTPBearer403(HTTPBearer): 1abcdefg
9 def make_not_authenticated_error(self) -> HTTPException: 1abcdefg
10 return HTTPException( 1hijklmn
11 status_code=status.HTTP_403_FORBIDDEN, detail="Not authenticated"
12 )
15CredentialsDep = Annotated[HTTPAuthorizationCredentials, Depends(HTTPBearer403())] 1abcdefg
18@app.get("/me") 1abcdefg
19def read_me(credentials: CredentialsDep): 1abcdefg
20 return {"message": "You are authenticated", "token": credentials.credentials} 1opqrstu