Skip to content

GetAccessToken

This module contains functions for getting the access token and authentication code for the AniList API.

authorization_url module-attribute

authorization_url = 'https://anilist.co/api/v2/oauth/authorize'

Get_Access_Token

Get_Access_Token(app: object) -> Union[str, None]

Retrieves the AniList API access token from environment variables or opens the authorization URL in the web browser.

PARAMETER DESCRIPTION
app

The application object.

TYPE: object

RETURNS DESCRIPTION
str

The access token, or None if the client ID is not found.

TYPE: Union[str, None]

Source code in AnilistMangaUpdater/API/GetAccessToken.py
def Get_Access_Token(app: object) -> Union[str, None]:
    """
    Retrieves the AniList API access token from environment variables
    or opens the authorization URL in the web browser.

    Parameters:
        app (object): The application object.

    Returns:
        str: The access token, or None if the client ID is not found.
    """
    client_id = os.environ.get("ANILIST_CLIENT_ID")
    if client_id is None:
        app.update_terminal(
            "No client ID found. Please enter your AniList client ID with the " "'Set API Values' button."
        )
        return None

    auth_url = f"{authorization_url}?client_id={client_id}&response_type=token"
    if platform.system() == "Linux":
        app.update_terminal("Please open the following URL in your web browser and follow the instructions:")
        app.update_terminal(auth_url)
    else:
        webbrowser.open(auth_url)

    return Get_Authentication_Code()

Get_Authentication_Code

Get_Authentication_Code() -> Union[str, None]

Checks for the presence of the access token in the environment variables in a loop.

RETURNS DESCRIPTION
str

The access token once it's found.

TYPE: Union[str, None]

Source code in AnilistMangaUpdater/API/GetAccessToken.py
def Get_Authentication_Code() -> Union[str, None]:
    """
    Checks for the presence of the access token in the environment variables in a loop.

    Returns:
        str: The access token once it's found.
    """
    while True:
        if os.environ.get("ACCESS_TOKEN") is not None:
            return os.environ.get("ACCESS_TOKEN")
        time.sleep(0.5)