ccproxy.auth.oauth.registry¶
ccproxy.auth.oauth.registry
¶
OAuth Provider Registry for dynamic provider management.
This module provides a central registry where plugins can register their OAuth providers at runtime, enabling dynamic discovery and management of OAuth flows.
CliAuthConfig
dataclass
¶
CliAuthConfig(
preferred_flow=browser,
callback_port=8080,
callback_path="/callback",
fixed_redirect_uri=None,
manual_redirect_uri=None,
supports_manual_code=True,
supports_device_flow=False,
)
CLI authentication configuration for OAuth providers.
OAuthProviderProtocol
¶
Bases: Protocol
Protocol for OAuth provider implementations.
provider_display_name
property
¶
Display name for UI (e.g., 'Claude API', 'OpenAI Codex').
cli
property
¶
CLI authentication configuration for this provider.
Returns:
| Type | Description |
|---|---|
CliAuthConfig
|
Configuration object specifying CLI flow preferences and capabilities |
get_authorization_url
async
¶
Get the authorization URL for OAuth flow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
str
|
OAuth state parameter for CSRF protection |
required |
code_verifier
|
str | None
|
PKCE code verifier (if PKCE is supported) |
None
|
redirect_uri
|
str | None
|
Redirect URI for OAuth callback |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Authorization URL to redirect user to |
Source code in ccproxy/auth/oauth/registry.py
handle_callback
async
¶
Handle OAuth callback and exchange code for tokens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
Authorization code from OAuth callback |
required |
state
|
str
|
State parameter for validation |
required |
code_verifier
|
str | None
|
PKCE code verifier (if PKCE is used) |
None
|
redirect_uri
|
str | None
|
Redirect URI used in the authorization request |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
Provider-specific credentials object |
Source code in ccproxy/auth/oauth/registry.py
refresh_access_token
async
¶
revoke_token
async
¶
Revoke an access or refresh token.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token
|
str
|
Token to revoke |
required |
get_provider_info
¶
Get provider information for discovery.
Returns:
| Type | Description |
|---|---|
OAuthProviderInfo
|
Provider information |
get_storage
¶
Get storage implementation for this provider.
Returns:
| Type | Description |
|---|---|
Any
|
Storage implementation or None |
get_credential_summary
¶
start_device_flow
async
¶
Start OAuth device code flow.
Returns:
| Type | Description |
|---|---|
tuple[str, str, str, int]
|
Tuple of (device_code, user_code, verification_uri, expires_in) |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If device flow is not supported |
Source code in ccproxy/auth/oauth/registry.py
complete_device_flow
async
¶
Complete OAuth device code flow by polling for authorization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device_code
|
str
|
Device code from start_device_flow |
required |
interval
|
int
|
Polling interval in seconds |
required |
expires_in
|
int
|
Code expiration time in seconds |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Provider-specific credentials object |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If device flow is not supported |
Source code in ccproxy/auth/oauth/registry.py
exchange_manual_code
async
¶
Exchange manually entered authorization code for tokens.
This method handles the case where users manually copy/paste authorization codes in restricted environments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
Authorization code entered manually by user |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Provider-specific credentials object |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If manual code entry is not implemented |
Source code in ccproxy/auth/oauth/registry.py
save_credentials
async
¶
Save credentials using provider's storage mechanism.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials
|
Any
|
Provider-specific credentials object |
required |
custom_path
|
Any | None
|
Optional custom storage path |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if saved successfully, False otherwise |
Source code in ccproxy/auth/oauth/registry.py
OAuthRegistry
¶
Central registry for OAuth providers.
This registry allows plugins to register their OAuth providers at runtime, enabling dynamic discovery and management of OAuth authentication flows.
Source code in ccproxy/auth/oauth/registry.py
register
¶
Register an OAuth provider from a plugin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider
|
OAuthProviderProtocol
|
OAuth provider implementation |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If provider with same name already registered |
Source code in ccproxy/auth/oauth/registry.py
unregister
¶
Unregister an OAuth provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider_name
|
str
|
Name of provider to unregister |
required |
Source code in ccproxy/auth/oauth/registry.py
get
¶
Get a registered OAuth provider by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider_name
|
str
|
Name of the provider |
required |
Returns:
| Type | Description |
|---|---|
OAuthProviderProtocol | None
|
OAuth provider instance or None if not found |
Source code in ccproxy/auth/oauth/registry.py
list
¶
List all registered OAuth providers.
Returns:
| Type | Description |
|---|---|
dict[str, OAuthProviderInfo]
|
Dictionary mapping provider names to their info |
Source code in ccproxy/auth/oauth/registry.py
has
¶
get_info
¶
Get information about a specific provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider_name
|
str
|
Name of the provider |
required |
Returns:
| Type | Description |
|---|---|
OAuthProviderInfo | None
|
Provider information or None if not found |
Source code in ccproxy/auth/oauth/registry.py
clear
¶
Clear all registered providers.
This is mainly useful for testing or shutdown scenarios.