# @oauthtoken

## Overview

The `@oauthtoken` decorator marks a function as handling OAuth tokens, enabling the function to be automatically recognized as part of an OAuth workflow.

## Syntax

```python
@oauthtoken
def function_name(self, access_token: str, expires_in: Optional[int] = None) -> None:
```

> **Note:** This decorator always applies to the same method signature, but the method itself can have any name.

## 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:
    """
    Base class for all Microsoft Books.

    OAuth Arguments:
        TENANT_ID: The tenant ID of the Azure AD directory.

    OAuth Labels:
        TENANT_ID: Tenant ID
    """

    _acquired_token: Optional[AcquiredToken] = None
    _headers: Optional[dict] = None

    def __init__(self):
        """
        Initializes an instance of the class.
        """
        self._acquired_token = None
        self._headers = None

    @oauthtoken
    def handle_token(self, access_token: str, expires_in: Optional[int] = None) -> None:
        """
        Handles the OAuth token.

        Args:
            access_token (str): The OAuth access token.
            expires_in (Optional[int]): The expiration time of the token, in seconds.

        Labels:
            access_token: OAuth Access Token
            expires_in: Token Expiration Time
        """
        self._acquired_token = AcquiredToken(access_token, expires_in or 3600)

```


---

# 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/oauthtoken-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.
