@ -9,7 +9,7 @@ from fastapi.security.base import SecurityBase
from fastapi . security . utils import get_authorization_scheme_param
from fastapi . security . utils import get_authorization_scheme_param
from pydantic import BaseModel
from pydantic import BaseModel
from starlette . requests import Request
from starlette . requests import Request
from starlette . status import HTTP_401_UNAUTHORIZED , HTTP_403_FORBIDDEN
from starlette . status import HTTP_401_UNAUTHORIZED
from typing_extensions import Annotated , Doc
from typing_extensions import Annotated , Doc
@ -87,7 +87,7 @@ class HTTPBase(SecurityBase):
if not ( authorization and scheme and credentials ) :
if not ( authorization and scheme and credentials ) :
if self . auto_error :
if self . auto_error :
raise HTTPException (
raise HTTPException (
status_code = HTTP_403_FORBIDDEN , detail = " Not authenticated "
status_code = HTTP_401_UNAUTHORIZED , detail = " Not authenticated "
)
)
else :
else :
return None
return None
@ -306,14 +306,14 @@ class HTTPBearer(HTTPBase):
if not ( authorization and scheme and credentials ) :
if not ( authorization and scheme and credentials ) :
if self . auto_error :
if self . auto_error :
raise HTTPException (
raise HTTPException (
status_code = HTTP_403_FORBIDDEN , detail = " Not authenticated "
status_code = HTTP_401_UNAUTHORIZED , detail = " Not authenticated "
)
)
else :
else :
return None
return None
if scheme . lower ( ) != " bearer " :
if scheme . lower ( ) != " bearer " :
if self . auto_error :
if self . auto_error :
raise HTTPException (
raise HTTPException (
status_code = HTTP_403_FORBIDDEN ,
status_code = HTTP_401_UNAUTHORIZED ,
detail = " Invalid authentication credentials " ,
detail = " Invalid authentication credentials " ,
)
)
else :
else :
@ -408,14 +408,14 @@ class HTTPDigest(HTTPBase):
if not ( authorization and scheme and credentials ) :
if not ( authorization and scheme and credentials ) :
if self . auto_error :
if self . auto_error :
raise HTTPException (
raise HTTPException (
status_code = HTTP_403_FORBIDDEN , detail = " Not authenticated "
status_code = HTTP_401_UNAUTHORIZED , detail = " Not authenticated "
)
)
else :
else :
return None
return None
if scheme . lower ( ) != " digest " :
if scheme . lower ( ) != " digest " :
if self . auto_error :
if self . auto_error :
raise HTTPException (
raise HTTPException (
status_code = HTTP_403_FORBIDDEN ,
status_code = HTTP_401_UNAUTHORIZED ,
detail = " Invalid authentication credentials " ,
detail = " Invalid authentication credentials " ,
)
)
else :
else :