# @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

```python
@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

<table><thead><tr><th width="209.953125">Parameter</th><th width="146.4609375">Type</th><th width="107.3125">Required</th><th>Description</th></tr></thead><tbody><tr><td><code>id</code></td><td>str</td><td>Yes</td><td>The unique identifier for the OAuth configuration.</td></tr><tr><td><code>provider</code></td><td>OAuthProvider</td><td>Yes</td><td><p>The OAuth provider:</p><ul><li>OAuthProvider.MICROSOFT</li><li>OAuthProvider.GOOGLE</li></ul></td></tr><tr><td><code>flows</code></td><td>List[OAuthFlow]</td><td>Optional</td><td>A list of OAuth flows.</td></tr><tr><td><code>authorize_endpoint</code></td><td>str</td><td>Yes</td><td>The authorization endpoint URL for the OAuth provider.</td></tr><tr><td><code>token_endpoint</code></td><td>str</td><td>Yes</td><td>The token endpoint URL for exchanging the authorization code for a token.</td></tr><tr><td><code>scopes</code></td><td>List[str]</td><td>Optional</td><td>A list of scopes required by the OAuth provider for the authenticated requests.</td></tr></tbody></table>

## Example

```python
@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
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.kognitos.com/legacy/legacy-experience/books/custom-books/api-reference/decorators/oauth-decorator.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
