ccproxy.plugins.copilot.oauth.provider¶
ccproxy.plugins.copilot.oauth.provider
¶
OAuth provider implementation for GitHub Copilot.
CopilotOAuthProvider
¶
CopilotOAuthProvider(
config=None,
storage=None,
http_client=None,
hook_manager=None,
detection_service=None,
)
Bases: ProfileLoggingMixin
GitHub Copilot OAuth provider implementation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
CopilotOAuthConfig | None
|
OAuth configuration |
None
|
storage
|
CopilotOAuthStorage | None
|
Token storage |
None
|
http_client
|
AsyncClient | None
|
Optional HTTP client for request tracing |
None
|
hook_manager
|
Any | None
|
Optional hook manager for events |
None
|
detection_service
|
CLIDetectionService | None
|
Optional CLI detection service |
None
|
Source code in ccproxy/plugins/copilot/oauth/provider.py
requires_client_secret
property
¶
Whether this provider requires a client secret.
get_authorization_url
async
¶
Get the authorization URL for GitHub Device Code Flow.
For device code flow, this returns the device authorization endpoint. The actual user verification happens at the verification_uri returned by start_device_flow().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
str
|
OAuth state parameter (not used in device flow) |
required |
code_verifier
|
str | None
|
PKCE code verifier (not used in device flow) |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Device authorization URL |
Source code in ccproxy/plugins/copilot/oauth/provider.py
start_device_flow
async
¶
Start the GitHub device code authorization flow.
Returns:
| Type | Description |
|---|---|
tuple[str, str, str, int]
|
Tuple of (device_code, user_code, verification_uri, expires_in) |
Source code in ccproxy/plugins/copilot/oauth/provider.py
complete_device_flow
async
¶
Complete the device flow authorization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device_code
|
str
|
Device code from start_device_flow |
required |
interval
|
int
|
Polling interval in seconds |
5
|
expires_in
|
int
|
Code expiration time in seconds |
900
|
Returns:
| Type | Description |
|---|---|
CopilotCredentials
|
Complete Copilot credentials |
Source code in ccproxy/plugins/copilot/oauth/provider.py
handle_callback
async
¶
Handle OAuth callback (not used in device flow).
This method is required by the CLI flow protocol but not used for device code flow. Use complete_device_flow instead.
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 authorization (optional) |
None
|
Source code in ccproxy/plugins/copilot/oauth/provider.py
exchange_code
async
¶
Exchange authorization code for token (not used in device flow).
This method is required by the OAuth protocol but not used for device code flow. Use complete_device_flow instead.
Source code in ccproxy/plugins/copilot/oauth/provider.py
refresh_token
async
¶
Refresh access token using refresh token.
For Copilot, this refreshes the Copilot service token using the stored OAuth token.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
refresh_token
|
str
|
Not used for Copilot (uses OAuth token instead) |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Token information |
Source code in ccproxy/plugins/copilot/oauth/provider.py
get_user_profile
async
¶
Get user profile information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
access_token
|
str | None
|
Optional OAuth access token (not Copilot token) |
None
|
Returns:
| Type | Description |
|---|---|
StandardProfileFields
|
User profile information |
Source code in ccproxy/plugins/copilot/oauth/provider.py
get_standard_profile
async
¶
Get standardized profile information from credentials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials
|
Any | None
|
Copilot credentials object (optional) |
None
|
Returns:
| Type | Description |
|---|---|
StandardProfileFields | None
|
Standardized profile fields or None if not available |
Source code in ccproxy/plugins/copilot/oauth/provider.py
get_token_info
async
¶
Get current token information.
Returns:
| Type | Description |
|---|---|
CopilotTokenInfo | None
|
Token information if available |
Source code in ccproxy/plugins/copilot/oauth/provider.py
get_token_snapshot
async
¶
Return a token snapshot built from stored credentials.
Source code in ccproxy/plugins/copilot/oauth/provider.py
is_authenticated
async
¶
Check if user is authenticated with valid tokens.
Returns:
| Type | Description |
|---|---|
bool
|
True if authenticated with valid tokens |
Source code in ccproxy/plugins/copilot/oauth/provider.py
get_copilot_token
async
¶
Get current Copilot service token for API requests.
Returns:
| Type | Description |
|---|---|
str | None
|
Copilot token if available and valid, None otherwise |
Source code in ccproxy/plugins/copilot/oauth/provider.py
ensure_oauth_token
async
¶
Ensure we have a valid OAuth token.
Returns:
| Type | Description |
|---|---|
str
|
Valid OAuth token |
Raises:
| Type | Description |
|---|---|
ValueError
|
If unable to get valid token |
Source code in ccproxy/plugins/copilot/oauth/provider.py
logout
async
¶
get_storage
¶
load_credentials
async
¶
Load credentials from provider's storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
custom_path
|
Any | None
|
Optional custom storage path (Path object) |
None
|
Returns:
| Type | Description |
|---|---|
Any | None
|
Credentials if found, None otherwise |
Source code in ccproxy/plugins/copilot/oauth/provider.py
save_credentials
async
¶
Save credentials to storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials
|
CopilotCredentials | None
|
Copilot credentials to save (None to clear) |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if save was successful |
Source code in ccproxy/plugins/copilot/oauth/provider.py
create_token_manager
async
¶
Create a token manager instance wired to this provider's context.
Source code in ccproxy/plugins/copilot/oauth/provider.py
cleanup
async
¶
get_provider_info
¶
Get provider information for registry.
Source code in ccproxy/plugins/copilot/oauth/provider.py
exchange_manual_code
async
¶
Exchange manual authorization code for tokens.
Note: Copilot primarily uses device code flow, but this method is provided for completeness.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
Authorization code from manual entry |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Copilot credentials object |