Skip to main content

OAuth2PasswordBearer

OAuth2 flow for authentication using a bearer token obtained with a password. An instance of it would be used as a dependency.

Attributes

AttributeTypeDescription
tokenUrlstrThe URL to obtain the OAuth2 token. This would be the path operation that has OAuth2PasswordRequestForm as a dependency.
scheme_name`strNone` = None
scopes`dict[str, str]None` = None
description`strNone` = None
auto_errorbool = TrueBy 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`strNone` = 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

NameTypeDescription
tokenUrlstrThe URL to obtain the OAuth2 token, typically the path operation using OAuth2PasswordRequestForm.
scheme_name`strNone` = None
scopes`dict[str, str]None` = None
description`strNone` = None
auto_errorbool = TrueIf True, missing Authorization headers result in an error; if False, the dependency returns None.
refreshUrl`strNone` = 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

NameTypeDescription
tokenUrlstrThe URL path where the client can exchange a username and password for an OAuth2 token.
scheme_name`strNone` = None
scopes`dict[str, str]None` = None
description`strNone` = None
auto_errorbool = TrueDetermines if the dependency should raise an HTTP 401 exception automatically when the Authorization header is missing or invalid.
refreshUrl`strNone` = None