Skip to main content

OAuth2AuthorizationCodeBearer

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

Attributes

AttributeTypeDescription
modelOAuth2ModelThe OpenAPI security scheme model containing the authorizationCode flow details including URLs and scopes.
scheme_name`strNone`
auto_errorbool = TrueIf set to False, the dependency result will be None instead of raising an error when the HTTP Authorization header is missing.

Constructor

Signature

def OAuth2AuthorizationCodeBearer(
authorizationUrl: str,
tokenUrl: str,
refreshUrl: str | None = None,
scheme_name: str | None = None,
scopes: dict[str, str]| None = None,
description: str | None = None,
auto_error: bool = True
)

Parameters

NameTypeDescription
authorizationUrlstrThe URL to redirect the user to for authorization.
tokenUrlstrThe URL to obtain the OAuth2 token.
refreshUrl`strNone` = None
scheme_name`strNone` = None
scopes`dict[str, str]None` = None
description`strNone` = None
auto_errorbool = TrueIf True, missing authorization headers trigger an error; if False, the dependency returns None.

Signature

def OAuth2AuthorizationCodeBearer(
authorizationUrl: str,
tokenUrl: str,
refreshUrl: str | None = None,
scheme_name: str | None = None,
scopes: dict[str, str]| None = None,
description: str | None = None,
auto_error: bool = True
) - > null

Parameters

NameTypeDescription
authorizationUrlstrThe URL where the user is redirected to authorize the application and obtain an authorization code.
tokenUrlstrThe URL used by the application to exchange the authorization code for an access token.
refreshUrl`strNone` = None
scheme_name`strNone` = None
scopes`dict[str, str]None` = None
description`strNone` = None
auto_errorbool = TrueDetermines if the dependency should raise an HTTP 401 error automatically when the Authorization header is missing or invalid.