ccproxy.services.credentials¶
ccproxy.services.credentials
¶
Credentials management package.
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.
OAuthCallbackError
¶
Bases: OAuthError
OAuth callback failed.
OAuthError
¶
Bases: AuthenticationError
Base OAuth error.
OAuthLoginError
¶
Bases: OAuthError
OAuth login failed.
OAuthTokenRefreshError
¶
Bases: OAuthError
OAuth token refresh failed.
AccountInfo
¶
OAuthToken
¶
JsonFileStorage
¶
Bases: TokenStorage
JSON file storage implementation for Claude credentials with keyring fallback.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
Path
|
Path to the JSON credentials file |
required |
Source code in ccproxy/auth/storage/json_file.py
load
async
¶
Load credentials from JSON file .
Returns:
Type | Description |
---|---|
ClaudeCredentials | None
|
Parsed credentials if found and valid, None otherwise |
Raises:
Type | Description |
---|---|
CredentialsInvalidError
|
If the JSON file is invalid |
CredentialsStorageError
|
If there's an error reading the file |
Source code in ccproxy/auth/storage/json_file.py
save
async
¶
Save credentials to both keyring and JSON file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
credentials
|
ClaudeCredentials
|
Credentials to save |
required |
Returns:
Type | Description |
---|---|
bool
|
True if saved successfully, False otherwise |
Raises:
Type | Description |
---|---|
CredentialsStorageError
|
If there's an error writing the file |
Source code in ccproxy/auth/storage/json_file.py
exists
async
¶
Check if credentials file exists.
Returns:
Type | Description |
---|---|
bool
|
True if file exists, False otherwise |
delete
async
¶
Delete credentials from both keyring and file.
Returns:
Type | Description |
---|---|
bool
|
True if deleted successfully, False otherwise |
Raises:
Type | Description |
---|---|
CredentialsStorageError
|
If there's an error deleting the file |
Source code in ccproxy/auth/storage/json_file.py
CredentialsStorageBackend
¶
Bases: ABC
Abstract interface for token storage operations.
load
abstractmethod
async
¶
Load credentials from storage.
Returns:
Type | Description |
---|---|
ClaudeCredentials | None
|
Parsed credentials if found and valid, None otherwise |
save
abstractmethod
async
¶
Save credentials to storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
credentials
|
ClaudeCredentials
|
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 |
CredentialsManager
¶
Manager for Claude credentials with storage and OAuth support.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
AuthSettings | None
|
Credentials configuration (uses defaults if not provided) |
None
|
storage
|
TokenStorage | None
|
Storage backend (uses JSON file storage if not provided) |
None
|
oauth_client
|
OAuthClient | None
|
OAuth client (creates one if not provided) |
None
|
http_client
|
AsyncClient | None
|
HTTP client for OAuth operations |
None
|
Source code in ccproxy/services/credentials/manager.py
find_credentials_file
async
¶
Find existing credentials file in configured paths.
Returns:
Type | Description |
---|---|
Path | None
|
Path to credentials file if found, None otherwise |
Source code in ccproxy/services/credentials/manager.py
load
async
¶
Load credentials from storage.
Returns:
Type | Description |
---|---|
ClaudeCredentials | None
|
Credentials if found and valid, None otherwise |
Source code in ccproxy/services/credentials/manager.py
save
async
¶
Save credentials to storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
credentials
|
ClaudeCredentials
|
Credentials to save |
required |
Returns:
Type | Description |
---|---|
bool
|
True if saved successfully, False otherwise |
Source code in ccproxy/services/credentials/manager.py
login
async
¶
Perform OAuth login and save credentials.
Returns:
Type | Description |
---|---|
ClaudeCredentials
|
New credentials from login |
Raises:
Type | Description |
---|---|
OAuthLoginError
|
If login fails |
Source code in ccproxy/services/credentials/manager.py
get_valid_credentials
async
¶
Get valid credentials, refreshing if necessary.
Returns:
Type | Description |
---|---|
ClaudeCredentials
|
Valid credentials |
Raises:
Type | Description |
---|---|
CredentialsNotFoundError
|
If no credentials found |
CredentialsExpiredError
|
If credentials expired and refresh fails |
Source code in ccproxy/services/credentials/manager.py
get_access_token
async
¶
Get valid access token, refreshing if necessary.
Returns:
Type | Description |
---|---|
str
|
Access token string |
Raises:
Type | Description |
---|---|
CredentialsNotFoundError
|
If no credentials found |
CredentialsExpiredError
|
If credentials expired and refresh fails |
Source code in ccproxy/services/credentials/manager.py
refresh_token
async
¶
Refresh the access token without checking expiration.
This method directly refreshes the token regardless of whether it's expired. Useful for force-refreshing tokens or testing.
Returns:
Type | Description |
---|---|
ClaudeCredentials
|
Updated credentials with new token |
Raises:
Type | Description |
---|---|
CredentialsNotFoundError
|
If no credentials found |
RuntimeError
|
If OAuth client not initialized |
ValueError
|
If no refresh token available |
Exception
|
If token refresh fails |
Source code in ccproxy/services/credentials/manager.py
fetch_user_profile
async
¶
Fetch user profile information.
Returns:
Type | Description |
---|---|
UserProfile | None
|
UserProfile if successful, None otherwise |
Source code in ccproxy/services/credentials/manager.py
get_account_profile
async
¶
Get saved account profile information.
Returns:
Type | Description |
---|---|
UserProfile | None
|
UserProfile if available, None otherwise |
validate
async
¶
Validate current credentials.
Returns:
Type | Description |
---|---|
ValidationResult
|
ValidationResult with credentials status and details |
Source code in ccproxy/services/credentials/manager.py
logout
async
¶
Delete stored credentials.
Returns:
Type | Description |
---|---|
bool
|
True if deleted successfully, False otherwise |
Source code in ccproxy/services/credentials/manager.py
OAuthClient
¶
OAuth client for handling Anthropic OAuth flows.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
OAuthSettings | None
|
OAuth configuration, uses default if not provided |
None
|
Source code in ccproxy/services/credentials/oauth_client.py
generate_pkce_pair
¶
Generate PKCE code verifier and challenge pair.
Returns:
Type | Description |
---|---|
tuple[str, str]
|
Tuple of (code_verifier, code_challenge) |
Source code in ccproxy/services/credentials/oauth_client.py
build_authorization_url
¶
Build authorization URL for OAuth flow.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
|
str
|
State parameter for CSRF protection |
required |
code_challenge
|
str
|
PKCE code challenge |
required |
Returns:
Type | Description |
---|---|
str
|
Authorization URL |
Source code in ccproxy/services/credentials/oauth_client.py
exchange_code_for_tokens
async
¶
Exchange authorization code for access tokens.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
authorization_code
|
str
|
Authorization code from callback |
required |
code_verifier
|
str
|
PKCE code verifier |
required |
Returns:
Type | Description |
---|---|
OAuthTokenResponse
|
Token response |
Raises:
Type | Description |
---|---|
HTTPError
|
If token exchange fails |
Source code in ccproxy/services/credentials/oauth_client.py
refresh_access_token
async
¶
Refresh access token using refresh token.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
refresh_token
|
str
|
Refresh token |
required |
Returns:
Type | Description |
---|---|
OAuthTokenResponse
|
New token response |
Raises:
Type | Description |
---|---|
HTTPError
|
If token refresh fails |
Source code in ccproxy/services/credentials/oauth_client.py
refresh_token
async
¶
Refresh token using refresh token - compatibility method for tests.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
refresh_token
|
str
|
Refresh token |
required |
Returns:
Type | Description |
---|---|
OAuthToken
|
New OAuth token |
Raises:
Type | Description |
---|---|
OAuthTokenRefreshError
|
If token refresh fails |
Source code in ccproxy/services/credentials/oauth_client.py
fetch_user_profile
async
¶
Fetch user profile information using access token.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
access_token
|
str
|
Valid OAuth access token |
required |
Returns:
Type | Description |
---|---|
UserProfile | None
|
User profile information |
Raises:
Type | Description |
---|---|
HTTPError
|
If profile fetch fails |
Source code in ccproxy/services/credentials/oauth_client.py
login
async
¶
Perform OAuth login flow.
Returns:
Type | Description |
---|---|
ClaudeCredentials
|
ClaudeCredentials with OAuth token |
Raises:
Type | Description |
---|---|
OAuthLoginError
|
If login fails |
OAuthCallbackError
|
If callback processing fails |
Source code in ccproxy/services/credentials/oauth_client.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 |
|