ccproxy.auth¶
ccproxy.auth
¶
Authentication module for centralized auth handling.
BearerTokenAuthManager
¶
Authentication manager for static bearer tokens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token
|
str
|
Bearer token string |
required |
Source code in ccproxy/auth/bearer.py
get_access_token
async
¶
Get the bearer token.
Returns:
| Type | Description |
|---|---|
str
|
Bearer token string |
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If token is invalid |
Source code in ccproxy/auth/bearer.py
get_credentials
async
¶
Bearer tokens do not expose structured credentials.
is_authenticated
async
¶
Check if bearer token is available.
Returns:
| Type | Description |
|---|---|
bool
|
True if token is available, False otherwise |
get_user_profile
async
¶
validate_credentials
async
¶
Validate that credentials are available and valid.
Returns:
| Type | Description |
|---|---|
bool
|
True if credentials are valid, False otherwise |
get_provider_name
¶
AuthenticationRequiredError
¶
Bases: AuthenticationError
Authentication is required but not provided.
CredentialsError
¶
Bases: AuthenticationError
Base credentials error.
CredentialsExpiredError
¶
Bases: CredentialsError
Credentials expired error.
CredentialsInvalidError
¶
Bases: CredentialsError
Credentials are invalid or malformed.
CredentialsNotFoundError
¶
Bases: CredentialsError
Credentials not found error.
CredentialsStorageError
¶
Bases: CredentialsError
Error occurred during credentials storage operations.
InsufficientPermissionsError
¶
Bases: AuthenticationError
Insufficient permissions for the requested operation.
InvalidTokenError
¶
Bases: AuthenticationError
Invalid or expired token.
OAuthError
¶
Bases: AuthenticationError
Base OAuth error.
OAuthTokenRefreshError
¶
Bases: OAuthError
OAuth token refresh failed.
AuthManager
¶
Bases: Protocol
Unified authentication manager protocol for all providers.
This protocol defines the complete interface that all authentication managers must implement, supporting both provider-specific methods (like Claude credentials) and generic methods (like auth headers) for maximum flexibility.
get_access_token
async
¶
Get valid access token.
Returns:
| Type | Description |
|---|---|
str
|
Access token string |
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If authentication fails |
get_credentials
async
¶
Get valid credentials.
Note: For non-Claude providers, this may return minimal/dummy credentials or raise AuthenticationError if not supported.
Returns:
| Type | Description |
|---|---|
BaseCredentials
|
Valid credentials |
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If authentication fails or not supported |
Source code in ccproxy/auth/manager.py
is_authenticated
async
¶
Check if current authentication is valid.
Returns:
| Type | Description |
|---|---|
bool
|
True if authenticated, False otherwise |
get_user_profile
async
¶
Get standardized user profile information.
Returns:
| Type | Description |
|---|---|
StandardProfileFields | None
|
Standardized profile details when available, otherwise |
StandardProfileFields | None
|
for providers that do not expose profile metadata. |
Source code in ccproxy/auth/manager.py
validate_credentials
async
¶
Validate that credentials are available and valid.
Returns:
| Type | Description |
|---|---|
bool
|
True if credentials are valid, False otherwise |
TokenStorage
¶
Bases: ABC, Generic[CredentialsT]
Abstract interface for token storage operations.
This is a generic interface that can work with any credential type that extends BaseModel (e.g., ClaudeCredentials, OpenAICredentials).
load
abstractmethod
async
¶
Load credentials from storage.
Returns:
| Type | Description |
|---|---|
CredentialsT | None
|
Parsed credentials if found and valid, None otherwise |
save
abstractmethod
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 |
exists
abstractmethod
async
¶
Check if credentials exist in storage.
Returns:
| Type | Description |
|---|---|
bool
|
True if credentials exist, False otherwise |
delete
abstractmethod
async
¶
Delete credentials from storage.
Returns:
| Type | Description |
|---|---|
bool
|
True if deleted successfully, False otherwise |
get_access_token
async
¶
Retrieve an access token from an authenticated manager.
Source code in ccproxy/auth/dependencies.py
get_auth_manager
async
¶
Return an authentication manager when credentials are required.
Source code in ccproxy/auth/dependencies.py
require_auth
async
¶
Enforce authentication, translating failures into HTTP errors.