HTTPBasic
HTTP Basic authentication.
Attributes
| Attribute | Type | Description |
|---|---|---|
| model | This attribute stores an instance of HTTPBaseModel, which defines the security scheme as 'basic' and includes the provided description. | |
| scheme_name | This attribute stores the security scheme name, which is included in the generated OpenAPI documentation and defaults to the class name if not explicitly set. | |
| realm | This attribute stores the HTTP Basic authentication realm, which is used in the WWW-Authenticate header for authentication challenges. | |
| auto_error | This attribute controls whether the class automatically raises an error if HTTP Basic authentication is not provided, or if it returns None instead for optional authentication scenarios. |
Constructor
Signature
def HTTPBasic(
scheme_name: str | None = None,
realm: str | None = None,
description: str | None = None,
auto_error: bool = True
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| scheme_name | `str | None` = None |
| realm | `str | None` = None |
| description | `str | None` = None |
| auto_error | bool = True | 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). |
Methods
make_authenticate_headers()
@classmethod
def make_authenticate_headers() - > dict[str, str]
Generates the WWW-Authenticate header dictionary for HTTP Basic authentication. This method is used to inform the client about the authentication scheme required, optionally including a realm.
Returns
| Type | Description |
|---|---|
dict[str, str] | A dictionary containing the WWW-Authenticate header, with the appropriate Basic scheme and realm if configured. |