Skip to content

ccproxy.plugins.copilot.oauth.models

ccproxy.plugins.copilot.oauth.models

GitHub Copilot-specific authentication models.

CopilotOAuthToken

Bases: BaseModel

OAuth token information for GitHub Copilot.

is_expired property

is_expired

Check if the token is expired.

expires_at_datetime property

expires_at_datetime

Get expiration as datetime object.

serialize_secret

serialize_secret(value)

Serialize SecretStr to plain string for JSON output.

Source code in ccproxy/plugins/copilot/oauth/models.py
@field_serializer("access_token", "refresh_token")
def serialize_secret(self, value: SecretStr | None) -> str | None:
    """Serialize SecretStr to plain string for JSON output."""
    return value.get_secret_value() if value else None

validate_tokens classmethod

validate_tokens(v)

Convert string values to SecretStr.

Source code in ccproxy/plugins/copilot/oauth/models.py
@field_validator("access_token", "refresh_token", mode="before")
@classmethod
def validate_tokens(cls, v: str | SecretStr | None) -> SecretStr | None:
    """Convert string values to SecretStr."""
    if v is None:
        return None
    if isinstance(v, str):
        return SecretStr(v)
    return v

CopilotEndpoints

Bases: BaseModel

Copilot API endpoints configuration.

CopilotTokenResponse

Bases: BaseModel

Copilot token exchange response.

is_expired property

is_expired

Check if the Copilot token is expired.

serialize_secret

serialize_secret(value)

Serialize SecretStr to plain string for JSON output.

Source code in ccproxy/plugins/copilot/oauth/models.py
@field_serializer("token")
def serialize_secret(self, value: SecretStr) -> str:
    """Serialize SecretStr to plain string for JSON output."""
    return value.get_secret_value()

serialize_datetime

serialize_datetime(value)

Serialize datetime back to Unix timestamp.

Source code in ccproxy/plugins/copilot/oauth/models.py
@field_serializer("expires_at")
def serialize_datetime(self, value: datetime | None) -> int | None:
    """Serialize datetime back to Unix timestamp."""
    if value is None:
        return None
    return int(value.timestamp())

validate_token classmethod

validate_token(v)

Convert string values to SecretStr.

Source code in ccproxy/plugins/copilot/oauth/models.py
@field_validator("token", mode="before")
@classmethod
def validate_token(cls, v: str | SecretStr) -> SecretStr:
    """Convert string values to SecretStr."""
    if isinstance(v, str):
        return SecretStr(v)
    return v

validate_expires_at classmethod

validate_expires_at(v)

Convert integer Unix timestamp or ISO string to datetime object.

Source code in ccproxy/plugins/copilot/oauth/models.py
@field_validator("expires_at", mode="before")
@classmethod
def validate_expires_at(cls, v: int | str | datetime | None) -> datetime | None:
    """Convert integer Unix timestamp or ISO string to datetime object."""
    if v is None:
        return None
    if isinstance(v, datetime):
        return v
    if isinstance(v, int):
        # Convert Unix timestamp to datetime
        return datetime.fromtimestamp(v, tz=UTC)
    if isinstance(v, str):
        # Try to parse as ISO string, fallback to Unix timestamp
        try:
            return datetime.fromisoformat(v.replace("Z", "+00:00"))
        except ValueError:
            try:
                return datetime.fromtimestamp(int(v), tz=UTC)
            except ValueError:
                return None
    return None

CopilotCredentials

Bases: BaseModel

Copilot credentials containing OAuth and Copilot tokens.

is_expired

is_expired()

Check if credentials are expired (BaseCredentials protocol).

Source code in ccproxy/plugins/copilot/oauth/models.py
def is_expired(self) -> bool:
    """Check if credentials are expired (BaseCredentials protocol)."""
    return self.oauth_token.is_expired

to_dict

to_dict()

Convert to dictionary for storage (BaseCredentials protocol).

Source code in ccproxy/plugins/copilot/oauth/models.py
def to_dict(self) -> dict[str, Any]:
    """Convert to dictionary for storage (BaseCredentials protocol)."""
    return self.model_dump(mode="json")

from_dict classmethod

from_dict(data)

Create from dictionary (BaseCredentials protocol).

Source code in ccproxy/plugins/copilot/oauth/models.py
@classmethod
def from_dict(cls, data: dict[str, Any]) -> "CopilotCredentials":
    """Create from dictionary (BaseCredentials protocol)."""
    return cls.model_validate(data)

refresh_updated_at

refresh_updated_at()

Update the updated_at timestamp.

Source code in ccproxy/plugins/copilot/oauth/models.py
def refresh_updated_at(self) -> None:
    """Update the updated_at timestamp."""
    self.updated_at = int(datetime.now(UTC).timestamp())

CopilotProfileInfo

Bases: BaseProfileInfo

GitHub profile information for Copilot users.

computed_display_name

computed_display_name()

Display name for UI.

Source code in ccproxy/plugins/copilot/oauth/models.py
@computed_field
def computed_display_name(self) -> str:
    """Display name for UI."""
    if self.display_name:
        return self.display_name
    return self.name or self.login

CopilotTokenInfo

Bases: BaseTokenInfo

Token information for Copilot credentials.

computed_is_expired

computed_is_expired()

Check if any token is expired.

Source code in ccproxy/plugins/copilot/oauth/models.py
@computed_field
def computed_is_expired(self) -> bool:
    """Check if any token is expired."""
    now = datetime.now(UTC)

    # Check OAuth token expiration
    if self.oauth_expires_at and now >= self.oauth_expires_at:
        return True

    # Check Copilot token expiration if available
    return bool(self.copilot_expires_at and now >= self.copilot_expires_at)

computed_display_name

computed_display_name()

Display name for UI.

Source code in ccproxy/plugins/copilot/oauth/models.py
@computed_field
def computed_display_name(self) -> str:
    """Display name for UI."""
    return f"GitHub Copilot ({self.account_type})"

DeviceCodeResponse

Bases: BaseModel

GitHub device code authorization response.

DeviceTokenPollResponse

Bases: BaseModel

Response from device code token polling.

is_pending property

is_pending

Check if authorization is still pending.

is_slow_down property

is_slow_down

Check if we should slow down polling.

is_expired property

is_expired

Check if device code has expired.

is_denied property

is_denied

Check if user denied authorization.

is_success property

is_success

Check if authorization was successful.