@oauth

Overview

The @oauth decorator is used to apply OAuth-based authentication to classes. It adds OAuth-specific metadata, such as endpoints, arguments, and provider details, to the class, enabling integration with OAuth services.

Syntax

@oauth(
    id=str,
    provider=OAuthProvider,
    flows=Optional[List[OAuthFlow]] = None,
    authorize_endpoint=str,
    token_endpoint=str,
    scopes=Optional[List[str]] = None,
)
class ClassName:
    """
    Class description
    """
    # Class implementation

Parameters

Parameter

Type

Required

Description

id

str

Yes

The unique identifier for the OAuth configuration.

provider

OAuthProvider

Yes

The OAuth provider:

  • OAuthProvider.MICROSOFT
  • OAuthProvider.GOOGLE

flows

List[OAuthFlow]

Optional

A list of OAuth flows.

authorize_endpoint

str

Yes

The authorization endpoint URL for the OAuth provider.

token_endpoint

str

Yes

The token endpoint URL for exchanging the authorization code for a token.

scopes

List[str]

Optional

A list of scopes required by the OAuth provider for the authenticated requests.

Example

@oauth(
    id="oauth",
    provider=OAuthProvider.MICROSOFT,
    flows=[OAuthFlow.AUTHORIZATION_CODE],
    authorize_endpoint="https://login.microsoftonline.com/{TENANT_ID}/oauth2/v2.0/authorize",
    token_endpoint="https://login.microsoftonline.com/{TENANT_ID}/oauth2/v2.0/token",
    scopes=[
        "https://graph.microsoft.com/Files.ReadWrite",
        "https://graph.microsoft.com/Sites.ReadWrite.All",
    ],
)
@book(name="MicrosoftBook")
class BaseMicrosoftBook

What’s Next