Skip to main content

HTTPBasic

HTTP Basic authentication.

Attributes

AttributeTypeDescription
modelThis attribute stores an instance of HTTPBaseModel, which defines the security scheme as 'basic' and includes the provided description.
scheme_nameThis attribute stores the security scheme name, which is included in the generated OpenAPI documentation and defaults to the class name if not explicitly set.
realmThis attribute stores the HTTP Basic authentication realm, which is used in the WWW-Authenticate header for authentication challenges.
auto_errorThis 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

NameTypeDescription
scheme_name`strNone` = None
realm`strNone` = None
description`strNone` = None
auto_errorbool = TrueBy 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

TypeDescription
dict[str, str]A dictionary containing the WWW-Authenticate header, with the appropriate Basic scheme and realm if configured.