ccproxy.auth.managers.base¶
ccproxy.auth.managers.base
¶
Base token manager for all authentication providers.
BaseTokenManager
¶
Bases: ABC, Generic[CredentialsT]
Base manager for token storage and refresh operations.
This generic base class provides common functionality for managing authentication tokens across different providers (OpenAI, Claude, etc.).
Class Type Parameters:
| Name | Bound or Constraints | Description | Default |
|---|---|---|---|
CredentialsT
|
The specific credential type (e.g., OpenAICredentials, ClaudeCredentials) |
required |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
storage
|
TokenStorage[CredentialsT]
|
Token storage backend that matches the credential type |
required |
Source code in ccproxy/auth/managers/base.py
refresh_grace_seconds
property
¶
Seconds before expiry when tokens should be proactively refreshed.
load_credentials
async
¶
Load credentials from storage.
Returns:
| Type | Description |
|---|---|
CredentialsT | None
|
Credentials if found and valid, None otherwise |
Source code in ccproxy/auth/managers/base.py
save_credentials
async
¶
Save credentials to storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials
|
CredentialsT
|
Credentials to save |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if saved successfully, False otherwise |
Source code in ccproxy/auth/managers/base.py
clear_credentials
async
¶
Clear stored credentials.
Returns:
| Type | Description |
|---|---|
bool
|
True if cleared successfully, False otherwise |
Source code in ccproxy/auth/managers/base.py
get_storage_location
¶
Get the storage location for credentials.
Returns:
| Type | Description |
|---|---|
str
|
Storage location description |
get_token_snapshot
async
¶
Return a lightweight snapshot of stored token metadata.
Source code in ccproxy/auth/managers/base.py
seconds_until_expiration
¶
Return seconds until the access token expires, if available.
Source code in ccproxy/auth/managers/base.py
should_refresh
¶
Determine whether credentials should be refreshed.
Source code in ccproxy/auth/managers/base.py
validate_token
async
¶
Check if stored token is valid and not expired.
Returns:
| Type | Description |
|---|---|
bool
|
True if valid, False otherwise |
Source code in ccproxy/auth/managers/base.py
refresh_token
abstractmethod
async
¶
Refresh the access token using the refresh token.
Returns:
| Type | Description |
|---|---|
CredentialsT | None
|
Updated credentials or None if refresh failed |
get_auth_status
async
¶
Get current authentication status.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with authentication status information |
Source code in ccproxy/auth/managers/base.py
is_expired
abstractmethod
¶
Check if credentials are expired.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials
|
CredentialsT
|
Credentials to check |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if expired, False otherwise |
get_account_id
abstractmethod
¶
Get account ID from credentials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials
|
CredentialsT
|
Credentials to extract account ID from |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Account ID if available, None otherwise |
Source code in ccproxy/auth/managers/base.py
get_expiration_time
¶
Get expiration time from credentials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials
|
CredentialsT
|
Credentials to extract expiration time from |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Expiration datetime if available, None otherwise |
Source code in ccproxy/auth/managers/base.py
get_profile
async
¶
Get profile information.
To be implemented by provider-specific managers. Returns provider-specific profile model.
get_profile_quick
async
¶
Get profile information without performing I/O or network when possible.
Default behavior returns any cached profile stored on the manager. Provider implementations may override to derive lightweight profiles directly from credentials (e.g., JWT claims) without remote calls.
Returns:
| Type | Description |
|---|---|
Any
|
Provider-specific profile model or None if unavailable |
Source code in ccproxy/auth/managers/base.py
get_unified_profile
async
¶
Get profile in a unified format across all providers.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with standardized fields plus provider-specific extras |
Source code in ccproxy/auth/managers/base.py
get_unified_profile_quick
async
¶
Get a lightweight unified profile across providers.
Uses cached or locally derivable data only. Implementations can override get_profile_quick() to provide provider-specific logic.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with standardized fields or empty dict if unavailable |
Source code in ccproxy/auth/managers/base.py
clear_cache
async
¶
Clear any cached data (profiles, etc.).
Should be called after token refresh or logout.
Source code in ccproxy/auth/managers/base.py
is_authenticated
async
¶
Check if current authentication is valid.
Returns:
| Type | Description |
|---|---|
bool
|
True if authenticated, False otherwise |
Source code in ccproxy/auth/managers/base.py
get_access_token
async
¶
Get valid access token from credentials.
Returns:
| Type | Description |
|---|---|
str | None
|
Access token if available and valid, None otherwise |
Source code in ccproxy/auth/managers/base.py
get_cached_auth_status
async
¶
Get current authentication status with caching.
This is a convenience method that wraps get_auth_status() with caching.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with authentication status information |