Skip to content

CopilotTokenStore

🛈 DocStrings

File-based token storage for Copilot OAuth.

Source code in src/llmling_models/auth/github_auth.py
class CopilotTokenStore:
    """File-based token storage for Copilot OAuth."""

    def __init__(self, path: Path = DEFAULT_TOKEN_PATH) -> None:
        self.path = path
        self.path.parent.mkdir(parents=True, exist_ok=True)

    def load(self) -> dict[str, str | float | None] | None:
        """Load stored credentials."""
        if not self.path.exists():
            return None
        try:
            return anyenv.load_json(self.path.read_text(), return_type=dict)
        except (anyenv.JsonLoadError, KeyError) as e:
            logger.warning("Failed to load copilot token from %s: %s", self.path, e)
            return None

    def save(self, data: dict[str, str | float | None]) -> None:
        """Save credentials."""
        write_private_json(self.path, data)

    def clear(self) -> None:
        """Remove stored credentials."""
        if self.path.exists():
            self.path.unlink()

clear

clear() -> None

Remove stored credentials.

Source code in src/llmling_models/auth/github_auth.py
def clear(self) -> None:
    """Remove stored credentials."""
    if self.path.exists():
        self.path.unlink()

load

load() -> dict[str, str | float | None] | None

Load stored credentials.

Source code in src/llmling_models/auth/github_auth.py
def load(self) -> dict[str, str | float | None] | None:
    """Load stored credentials."""
    if not self.path.exists():
        return None
    try:
        return anyenv.load_json(self.path.read_text(), return_type=dict)
    except (anyenv.JsonLoadError, KeyError) as e:
        logger.warning("Failed to load copilot token from %s: %s", self.path, e)
        return None

save

save(data: dict[str, str | float | None]) -> None

Save credentials.

Source code in src/llmling_models/auth/github_auth.py
def save(self, data: dict[str, str | float | None]) -> None:
    """Save credentials."""
    write_private_json(self.path, data)

:fa-brands-github: Show source on GitHub