> For the complete documentation index, see [llms.txt](https://docs.kognitos.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kognitos.com/legacy/legacy-experience/books/custom-books/api-reference/decorators/oauthtoken-decorator.md).

# @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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
