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.

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
) - > null

Parameters

NameTypeDescription
authorizationUrlstrThe URL to obtain the OAuth2 token.
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 = 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).