OAuth2PasswordBearer
OAuth2 flow for authentication using a bearer token obtained with a password. An instance of it would be used as a dependency.
Attributes
| Attribute | Type | Description |
|---|---|---|
| tokenUrl | str | The URL to obtain the OAuth2 token. This would be the path operation that has OAuth2PasswordRequestForm as a dependency. |
| scheme_name | `str | None` = None |
| scopes | `dict[str, str] | None` = None |
| description | `str | None` = None |
| auto_error | bool = True | By default, if no HTTP Authorization header is provided, required for OAuth2 authentication, it will automatically cancel the request and send the client an error. |
| refreshUrl | `str | None` = None |
Constructor
Signature
def OAuth2PasswordBearer(
tokenUrl: str,
scheme_name: str | None = None,
scopes: dict[str, str]| None = None,
description: str | None = None,
auto_error: bool = True,
refreshUrl: str | None = None
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| tokenUrl | str | The URL to obtain the OAuth2 token, typically the path operation using OAuth2PasswordRequestForm. |
| scheme_name | `str | None` = None |
| scopes | `dict[str, str] | None` = None |
| description | `str | None` = None |
| auto_error | bool = True | If True, missing Authorization headers result in an error; if False, the dependency returns None. |
| refreshUrl | `str | None` = None |
Signature
def OAuth2PasswordBearer(
tokenUrl: str,
scheme_name: str | None = None,
scopes: dict[str, str]| None = None,
description: str | None = None,
auto_error: bool = True,
refreshUrl: str | None = None
)
Parameters
| Name | Type | Description |
|---|---|---|
| tokenUrl | str | The URL path where the client can exchange a username and password for an OAuth2 token. |
| scheme_name | `str | None` = None |
| scopes | `dict[str, str] | None` = None |
| description | `str | None` = None |
| auto_error | bool = True | Determines if the dependency should raise an HTTP 401 exception automatically when the Authorization header is missing or invalid. |
| refreshUrl | `str | None` = None |