Coverage for docs_src/authentication_error_status_code/tutorial001_an_py39.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 typing import Annotated 1abcdef
3from fastapi import Depends, FastAPI, HTTPException, status 1abcdef
4from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer 1abcdef
6app = FastAPI() 1abcdef
9class HTTPBearer403(HTTPBearer): 1abcdef
10 def make_not_authenticated_error(self) -> HTTPException: 1abcdef
11 return HTTPException( 1ghijkl
12 status_code=status.HTTP_403_FORBIDDEN, detail="Not authenticated"
13 )
16CredentialsDep = Annotated[HTTPAuthorizationCredentials, Depends(HTTPBearer403())] 1abcdef
19@app.get("/me") 1abcdef
20def read_me(credentials: CredentialsDep): 1abcdef
21 return {"message": "You are authenticated", "token": credentials.credentials} 1mnopqr