HTTPBearer
HTTP Bearer token authentication.
Attributes
| Attribute | Type | Description |
|---|---|---|
| model | HTTPBearerModel | This attribute stores an instance of HTTPBearerModel, which encapsulates the bearer token format and description for OpenAPI documentation. |
| scheme_name | str | This attribute stores the security scheme name, which is included in the generated OpenAPI documentation (e.g., visible at /docs). |
| auto_error | bool | This attribute controls whether HTTPBearer automatically cancels the request and sends an error if the HTTP Bearer token is not provided, or if it returns None for optional authentication. |
Constructor
Signature
def HTTPBearer(
bearerFormat: Annotated[str | None, Doc("Bearer token format.")] = None,
scheme_name: Annotated[str | None, Doc("Security scheme name. It will be included in the generated OpenAPI(e.g. visible at `/docs`).")] = None,
description: Annotated[str | None, 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 Bearer token is not provided(in an `Authorization` header), `HTTPBearer` will automatically cancel the request and send the client an error. If `auto_error` is set to `False`, when the HTTP Bearer token 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 an HTTP Bearer token or in a cookie).")] = True
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| bearerFormat | `Annotated[str | None, Doc("Bearer token format.")]` = None |
| scheme_name | `Annotated[str | None, Doc("Security scheme name. It will be included in the generated OpenAPI(e.g. visible at /docs).")]` = None |
| description | `Annotated[str | None, 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 Bearer token is not provided(in an Authorizationheader),HTTPBearerwill automatically cancel the request and send the client an error. Ifauto_erroris set toFalse, when the HTTP Bearer token 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 an HTTP Bearer token or in a cookie).")] = True | By default, if the HTTP Bearer token is not provided (in an Authorization header), HTTPBearer will automatically cancel the request and send the client an error. If auto_error is set to False, when the HTTP Bearer token 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 an HTTP Bearer token or in a cookie). |