Skip to content

auth

appimage_updater.repositories.github.auth

GitHub authentication management for AppImage Updater.

This module handles GitHub token discovery and authentication for API requests. Supports multiple token sources with security-first priority ordering.

GitHubAuth(token=None)

Manages GitHub authentication token discovery and validation.

Parameters:

Name Type Description Default
token str | None

Optional explicit token to use (overrides discovery)

None
Source code in src/appimage_updater/repositories/github/auth.py
def __init__(self, token: str | None = None) -> None:
    """Initialize GitHub authentication.

    Args:
        token: Optional explicit token to use (overrides discovery)
    """
    self._token = token
    self._discovered_token: str | None = None

is_authenticated property

Check if GitHub authentication is available.

Returns:

Type Description
bool

True if a valid token is available

token property

Get the GitHub token, discovering it if not already found.

Returns:

Type Description
str | None

GitHub token string or None if no token found

get_auth_headers()

Get HTTP headers for GitHub API authentication.

Returns:

Type Description
dict[str, str]

Dictionary of headers to include in requests

Source code in src/appimage_updater/repositories/github/auth.py
def get_auth_headers(self) -> dict[str, str]:
    """Get HTTP headers for GitHub API authentication.

    Returns:
        Dictionary of headers to include in requests
    """
    headers = {
        "Accept": "application/vnd.github.v3+json",
        "User-Agent": self._get_user_agent(),
    }

    if self.is_authenticated:
        headers["Authorization"] = f"token {self.token}"

    return headers

get_rate_limit_info()

Get information about API rate limits.

Returns:

Type Description
dict[str, int | str]

Dictionary with rate limit information

Source code in src/appimage_updater/repositories/github/auth.py
def get_rate_limit_info(self) -> dict[str, int | str]:
    """Get information about API rate limits.

    Returns:
        Dictionary with rate limit information
    """
    if self.is_authenticated:
        return {
            "limit": 5000,  # Authenticated requests
            "period_hours": 1,
            "type": "authenticated",
        }
    else:
        return {
            "limit": 60,  # Anonymous requests
            "period_hours": 1,
            "type": "anonymous",
        }

get_github_auth(token=None)

Factory function to create GitHubAuth instance.

Parameters:

Name Type Description Default
token str | None

Optional explicit token to use

None

Returns:

Type Description
GitHubAuth

Configured GitHubAuth instance

Source code in src/appimage_updater/repositories/github/auth.py
def get_github_auth(token: str | None = None) -> GitHubAuth:
    """Factory function to create GitHubAuth instance.

    Args:
        token: Optional explicit token to use

    Returns:
        Configured GitHubAuth instance
    """
    return GitHubAuth(token=token)