|
|
|
@ -142,55 +142,18 @@ class HTTPBasic(HTTPBase): |
|
|
|
def __init__( |
|
|
|
self, |
|
|
|
*, |
|
|
|
scheme_name: Annotated[ |
|
|
|
Optional[str], |
|
|
|
Doc( |
|
|
|
""" |
|
|
|
Security scheme name. |
|
|
|
|
|
|
|
It will be included in the generated OpenAPI (e.g. visible at `/docs`). |
|
|
|
""" |
|
|
|
), |
|
|
|
] = None, |
|
|
|
realm: Annotated[str, Doc("HTTP Basic authentication realm.")] = "fastapi", |
|
|
|
description: Annotated[ |
|
|
|
Optional[str], |
|
|
|
Doc( |
|
|
|
""" |
|
|
|
Security scheme description. |
|
|
|
|
|
|
|
It will be included in the generated OpenAPI (e.g. visible at `/docs`). |
|
|
|
""" |
|
|
|
), |
|
|
|
] = None, |
|
|
|
auto_error: Annotated[ |
|
|
|
bool, |
|
|
|
Doc( |
|
|
|
""" |
|
|
|
By default, if the HTTP Basic authentication is not provided (a |
|
|
|
header), `HTTPBasic` will automatically cancel the request and send the |
|
|
|
client an error. |
|
|
|
|
|
|
|
If `auto_error` is set to `False`, when the HTTP Basic authentication |
|
|
|
is not available, instead of erroring out, the dependency result will |
|
|
|
be `None`. |
|
|
|
|
|
|
|
This is useful when you want to have optional authentication. |
|
|
|
|
|
|
|
It is also useful when you want to have authentication that can be |
|
|
|
provided in one of multiple optional ways (for example, in HTTP Basic |
|
|
|
authentication or in an HTTP Bearer token). |
|
|
|
""" |
|
|
|
), |
|
|
|
] = True, |
|
|
|
): |
|
|
|
scheme_name: Optional[str] = None, |
|
|
|
description: Optional[str] = None, |
|
|
|
auto_error: bool = True, |
|
|
|
): |
|
|
|
self.model = HTTPBaseModel(scheme="basic", description=description) |
|
|
|
self.scheme_name = scheme_name or self.__class__.__name__ |
|
|
|
self.realm = realm |
|
|
|
self.auto_error = auto_error |
|
|
|
|
|
|
|
|
|
|
|
def make_authenticate_headers(self) -> dict[str, str]: |
|
|
|
return {"WWW-Authenticate": f'Basic realm="{self.realm}"'} |
|
|
|
return {"WWW-Authenticate": "Basic"} |
|
|
|
|
|
|
|
|
|
|
|
async def __call__( # type: ignore |
|
|
|
self, request: Request |
|
|
|
|