Skip to content

ccproxy.plugins.oauth_claude.models

ccproxy.plugins.oauth_claude.models

Claude-specific authentication models.

ClaudeOAuthToken

Bases: BaseModel

OAuth token information from Claude credentials.

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/oauth_claude/models.py
@field_serializer("access_token", "refresh_token")
def serialize_secret(self, value: SecretStr) -> str:
    """Serialize SecretStr to plain string for JSON output."""
    return value.get_secret_value() if value else ""

validate_tokens classmethod

validate_tokens(v)

Convert string values to SecretStr.

Source code in ccproxy/plugins/oauth_claude/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

ClaudeCredentials

Bases: BaseModel

Claude credentials from the credentials file.

is_expired

is_expired()

Check if the credentials are expired.

Returns:

Type Description
bool

True if expired, False otherwise

Source code in ccproxy/plugins/oauth_claude/models.py
def is_expired(self) -> bool:
    """Check if the credentials are expired.

    Returns:
        True if expired, False otherwise
    """
    return self.claude_ai_oauth.is_expired

model_dump

model_dump(**kwargs)

Override model_dump to use by_alias=True by default.

Source code in ccproxy/plugins/oauth_claude/models.py
def model_dump(self, **kwargs: Any) -> dict[str, Any]:
    """Override model_dump to use by_alias=True by default."""
    kwargs.setdefault("by_alias", True)
    return super().model_dump(**kwargs)

to_dict

to_dict()

Convert to dictionary for storage.

Returns:

Type Description
dict[str, Any]

Dictionary representation

Source code in ccproxy/plugins/oauth_claude/models.py
def to_dict(self) -> dict[str, Any]:
    """Convert to dictionary for storage.

    Returns:
        Dictionary representation
    """
    return self.model_dump(mode="json", exclude_none=True)

from_dict classmethod

from_dict(data)

Create from dictionary.

Parameters:

Name Type Description Default
data dict[str, Any]

Dictionary containing credential data

required

Returns:

Type Description
ClaudeCredentials

ClaudeCredentials instance

Source code in ccproxy/plugins/oauth_claude/models.py
@classmethod
def from_dict(cls, data: dict[str, Any]) -> "ClaudeCredentials":
    """Create from dictionary.

    Args:
        data: Dictionary containing credential data

    Returns:
        ClaudeCredentials instance
    """
    return cls.model_validate(data)

ClaudeTokenWrapper

Bases: BaseTokenInfo

Wrapper for Claude credentials that adds computed properties.

This wrapper maintains the original ClaudeCredentials structure while providing a unified interface through BaseTokenInfo.

refresh_token_value property

refresh_token_value

Extract refresh token from Claude OAuth structure.

expires_at_datetime property

expires_at_datetime

Convert Claude's millisecond timestamp to datetime.

subscription_type property

subscription_type

Compute subscription type from stored profile info.

Attempts to read the Claude profile file ("~/.claude/.account.json") and derive the subscription from account flags: - "max" if has_claude_max is true - "pro" if has_claude_pro is true - "free" otherwise

Falls back to the token's own subscription_type if profile is unavailable.

scopes property

scopes

Get OAuth scopes.

access_token_value

access_token_value()

Extract access token from Claude OAuth structure.

Source code in ccproxy/plugins/oauth_claude/models.py
@computed_field
def access_token_value(self) -> str:
    """Extract access token from Claude OAuth structure."""
    return self.credentials.claude_ai_oauth.access_token.get_secret_value()

ClaudeProfileInfo

Bases: BaseProfileInfo

Claude-specific profile information from API.

Created from the /api/organizations/me endpoint response.

has_claude_pro property

has_claude_pro

Check if user has Claude Pro subscription.

has_claude_max property

has_claude_max

Check if user has Claude Max subscription.

organization_name property

organization_name

Get organization name if available.

from_api_response classmethod

from_api_response(data)

Create profile from Claude API response.

Parameters:

Name Type Description Default
data dict[str, Any]

Response from /api/organizations/me endpoint

required

Returns:

Type Description
ClaudeProfileInfo

ClaudeProfileInfo instance with all data preserved

Source code in ccproxy/plugins/oauth_claude/models.py
@classmethod
def from_api_response(cls, data: dict[str, Any]) -> "ClaudeProfileInfo":
    """Create profile from Claude API response.

    Args:
        data: Response from /api/organizations/me endpoint

    Returns:
        ClaudeProfileInfo instance with all data preserved
    """
    # Extract account information if present
    account = data.get("account", {})
    organization = data.get("organization", {})

    # Extract common fields for easy access
    account_id = account.get("uuid", "")
    email = account.get("email", "")
    display_name = account.get("full_name")

    # Store entire response in extras for complete information
    # This includes: has_claude_pro, has_claude_max, organization details, etc.
    return cls(
        account_id=account_id,
        email=email,
        display_name=display_name,
        extras=data,  # Preserve complete API response
    )