ccproxy.plugins.copilot.oauth¶
ccproxy.plugins.copilot.oauth
¶
OAuth implementation for GitHub Copilot plugin.
CopilotOAuthClient
¶
OAuth client for GitHub Copilot using Device Code Flow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
CopilotOAuthConfig
|
OAuth configuration |
required |
storage
|
CopilotOAuthStorage
|
Token storage |
required |
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/client.py
close
async
¶
start_device_flow
async
¶
Start the GitHub device code authorization flow.
Returns:
| Type | Description |
|---|---|
DeviceCodeResponse
|
Device code response with verification details |
Source code in ccproxy/plugins/copilot/oauth/client.py
poll_for_token
async
¶
Poll GitHub for OAuth token after user authorization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device_code
|
str
|
Device code from device flow |
required |
interval
|
int
|
Polling interval in seconds |
required |
expires_in
|
int
|
Code expiration time in seconds |
required |
Returns:
| Type | Description |
|---|---|
CopilotOAuthToken
|
OAuth token once authorized |
Raises:
| Type | Description |
|---|---|
TimeoutError
|
If device code expires |
ValueError
|
If user denies authorization |
Source code in ccproxy/plugins/copilot/oauth/client.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
exchange_for_copilot_token
async
¶
Exchange GitHub OAuth token for Copilot service token.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
oauth_token
|
CopilotOAuthToken
|
GitHub OAuth token |
required |
Returns:
| Type | Description |
|---|---|
CopilotTokenResponse
|
Copilot service token response |
Source code in ccproxy/plugins/copilot/oauth/client.py
get_user_profile
async
¶
Get user profile information from GitHub API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
oauth_token
|
CopilotOAuthToken
|
GitHub OAuth token |
required |
Returns:
| Type | Description |
|---|---|
CopilotProfileInfo
|
User profile information |
Source code in ccproxy/plugins/copilot/oauth/client.py
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 | |
to_standard_profile
¶
Convert Copilot profile info into StandardProfileFields.
Source code in ccproxy/plugins/copilot/oauth/client.py
get_standard_profile
async
¶
Fetch profile info and normalize it for generic consumers.
Source code in ccproxy/plugins/copilot/oauth/client.py
complete_authorization
async
¶
Complete the full authorization flow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device_code
|
str
|
Device code from device flow |
required |
interval
|
int
|
Polling interval |
required |
expires_in
|
int
|
Code expiration time |
required |
Returns:
| Type | Description |
|---|---|
CopilotCredentials
|
Complete Copilot credentials |
Source code in ccproxy/plugins/copilot/oauth/client.py
refresh_copilot_token
async
¶
Refresh the Copilot service token using stored OAuth token.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials
|
CopilotCredentials
|
Current credentials |
required |
Returns:
| Type | Description |
|---|---|
CopilotCredentials
|
Updated credentials with new Copilot token |
Source code in ccproxy/plugins/copilot/oauth/client.py
CopilotCredentials
¶
CopilotOAuthToken
¶
CopilotProfileInfo
¶
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 |
Source code in ccproxy/plugins/copilot/oauth/provider.py
CopilotOAuthStorage
¶
Bases: BaseJsonStorage[CopilotCredentials]
Storage implementation for Copilot OAuth credentials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials_path
|
Path | None
|
Path to credentials file (uses default if None) |
None
|
Source code in ccproxy/plugins/copilot/oauth/storage.py
save
async
¶
Store Copilot credentials to file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credentials
|
CopilotCredentials
|
Credentials to store |
required |
Source code in ccproxy/plugins/copilot/oauth/storage.py
load
async
¶
Load Copilot credentials from file.
Returns:
| Type | Description |
|---|---|
CopilotCredentials | None
|
Credentials if found and valid, None otherwise |
Source code in ccproxy/plugins/copilot/oauth/storage.py
delete
async
¶
update_oauth_token
async
¶
Update OAuth token in stored credentials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
oauth_token
|
CopilotOAuthToken
|
New OAuth token to store |
required |
Source code in ccproxy/plugins/copilot/oauth/storage.py
update_copilot_token
async
¶
Update Copilot service token in stored credentials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
copilot_token
|
CopilotTokenResponse
|
New Copilot token to store |
required |
Source code in ccproxy/plugins/copilot/oauth/storage.py
get_oauth_token
async
¶
Get OAuth token from stored credentials.
Returns:
| Type | Description |
|---|---|
CopilotOAuthToken | None
|
OAuth token if available, None otherwise |
Source code in ccproxy/plugins/copilot/oauth/storage.py
get_copilot_token
async
¶
Get Copilot service token from stored credentials.
Returns:
| Type | Description |
|---|---|
CopilotTokenResponse | None
|
Copilot token if available, None otherwise |