Skip to content

ccproxy.plugins.oauth_codex.storage

ccproxy.plugins.oauth_codex.storage

Token storage for Codex OAuth plugin.

CodexTokenStorage

CodexTokenStorage(storage_path=None)

Bases: BaseJsonStorage[OpenAICredentials]

Codex/OpenAI OAuth-specific token storage implementation.

Parameters:

Name Type Description Default
storage_path Path | None

Path to storage file

None
Source code in ccproxy/plugins/oauth_codex/storage.py
def __init__(self, storage_path: Path | None = None):
    """Initialize Codex token storage.

    Args:
        storage_path: Path to storage file
    """
    if storage_path is None:
        # Default to standard OpenAI credentials location
        storage_path = Path.home() / ".codex" / "auth.json"

    super().__init__(storage_path)
    self.provider_name = "codex"

save async

save(credentials)

Save OpenAI credentials.

Parameters:

Name Type Description Default
credentials OpenAICredentials

OpenAI credentials to save

required

Returns:

Type Description
bool

True if saved successfully, False otherwise

Source code in ccproxy/plugins/oauth_codex/storage.py
async def save(self, credentials: OpenAICredentials) -> bool:
    """Save OpenAI credentials.

    Args:
        credentials: OpenAI credentials to save

    Returns:
        True if saved successfully, False otherwise
    """
    try:
        # Convert to dict for storage
        data = credentials.model_dump(mode="json", exclude_none=True)

        # Use parent class's atomic write with backup
        await self._write_json(data)

        logger.info(
            "codex_oauth_credentials_saved",
            has_refresh_token=bool(credentials.refresh_token),
            storage_path=str(self.file_path),
            category="auth",
        )
        return True
    except Exception as e:
        logger.error(
            "codex_oauth_save_failed", error=str(e), exc_info=e, category="auth"
        )
        return False

load async

load()

Load OpenAI credentials.

Returns:

Type Description
OpenAICredentials | None

Stored credentials or None

Source code in ccproxy/plugins/oauth_codex/storage.py
async def load(self) -> OpenAICredentials | None:
    """Load OpenAI credentials.

    Returns:
        Stored credentials or None
    """
    try:
        # Use parent class's read method (avoid redundant exists() checks)
        data = await self._read_json()
        if not data:
            logger.debug(
                "codex_auth_file_empty",
                storage_path=str(self.file_path),
                category="auth",
            )
            return None

        credentials = OpenAICredentials.model_validate(data)
        logger.info(
            "codex_oauth_credentials_loaded",
            has_refresh_token=bool(credentials.refresh_token),
            category="auth",
        )
        return credentials
    except Exception as e:
        logger.error(
            "codex_oauth_credentials_load_error",
            error=str(e),
            exc_info=e,
            category="auth",
        )
        return None