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
| Attribute | Type | Description |
|---|---|---|
| model | OAuth2Model | The OpenAPI security scheme model containing the authorizationCode flow details including URLs and scopes. |
| scheme_name | `str | None` |
| auto_error | bool = True | If 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
| Name | Type | Description |
|---|---|---|
| authorizationUrl | str | The URL to redirect the user to for authorization. |
| tokenUrl | str | The URL to obtain the OAuth2 token. |
| refreshUrl | `str | None` = None |
| scheme_name | `str | None` = None |
| scopes | `dict[str, str] | None` = None |
| description | `str | None` = None |
| auto_error | bool = True | If 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
| Name | Type | Description |
|---|---|---|
| authorizationUrl | str | The URL where the user is redirected to authorize the application and obtain an authorization code. |
| tokenUrl | str | The URL used by the application to exchange the authorization code for an access token. |
| refreshUrl | `str | None` = None |
| 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 error automatically when the Authorization header is missing or invalid. |