Skip to content

auth

appimage_updater.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/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
    self._token_source: 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

token_source property

Get the source of the current token for logging/debugging.

Returns:

Type Description
str | None

String describing where the token was 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/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/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",
        }

log_auth_status()

Log current authentication status for debugging.

Source code in src/appimage_updater/github/auth.py
def log_auth_status(self) -> None:
    """Log current authentication status for debugging."""
    rate_info = self.get_rate_limit_info()

    if self.is_authenticated:
        logger.debug(f"GitHub API: Authenticated via {self.token_source}")
        logger.debug(f"Rate limit: {rate_info['limit']} requests/hour")
    else:
        logger.debug("GitHub API: Anonymous access (rate limited to 60 requests/hour)")
        logger.debug("Consider setting GITHUB_TOKEN environment variable for higher limits")

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/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)