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-04-06 01:24 +0000

1from typing import Annotated 1abcdef

2 

3from fastapi import Depends, FastAPI, HTTPException, status 1abcdef

4from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer 1abcdef

5 

6app = FastAPI() 1abcdef

7 

8 

9class HTTPBearer403(HTTPBearer): 1abcdef

10 def make_not_authenticated_error(self) -> HTTPException: 1abcdef

11 return HTTPException( 1ghij

12 status_code=status.HTTP_403_FORBIDDEN, detail="Not authenticated" 

13 ) 

14 

15 

16CredentialsDep = Annotated[HTTPAuthorizationCredentials, Depends(HTTPBearer403())] 1abcdef

17 

18 

19@app.get("/me") 1abcdef

20def read_me(credentials: CredentialsDep): 1abcdef

21 return {"message": "You are authenticated", "token": credentials.credentials} 1klmn