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.

Constructor

Signature

def OAuth2PasswordBearer(
tokenUrl: str = null,
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
tokenUrlstr = nullThe URL to obtain the OAuth2 token. This would be the path operation that has OAuth2PasswordRequestForm as a dependency. Read more about it in the FastAPI docs for Simple OAuth2 with Password and Bearer.
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. If auto_error is set to False, when the HTTP Authorization header 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, with OAuth2 or in a cookie).
refreshUrl`strNone` = None