Skip to main content

Module github_copilot

Module github_copilot 

Source
Expand description

GitHub Copilot OAuth (device authorization + broker-owned session mint).

Experimental. Device-flow endpoints are official GitHub OAuth. The session-mint path (GET /copilot_internal/v2/token) is community-observed and is not documented as a stable general-purpose third-party API. Do not describe it as officially supported.

Credential mapping:

  • OAuthCredentials.refresh = long-lived GitHub user token (broker-owned only)
  • OAuthCredentials.access = short-lived Copilot session token
  • OAuthCredentials.expires = session expiry (ms, with skew)

The long-lived GitHub token must never be vended, logged, or placed in broker wire types.

Structs§

DeviceAuthorization
InjectedHttpResponse
Minimal HTTP response used by the device-flow / mint state machine.
LoginHooks
SessionToken

Enums§

CopilotAuthError
Failures from the Copilot auth chain. Variants intentionally store no device codes, user codes, tokens, or Authorization headers so Display/Debug cannot leak them.
DevicePollOutcome
Outcome of one device-token poll (secret-safe; token only on Authorized).

Constants§

ACCESS_TOKEN_URL
Official GitHub OAuth token endpoint (device-code grant).
CLIENT_ID
Public native-client id observed in Copilot editor clients (VS Code lineage). Not a client secret. Provenance: community consensus + device-flow examples; not a first-class constant on docs.github.com. See docs/specs/github-copilot-oauth-spec.md.
CONNECT_TIMEOUT
Connect timeout for production device/poll/mint HTTP.
DEFAULT_VERIFICATION_URI
Default verification page (official docs.github.com device flow).
DEVICE_CODE_URL
Official GitHub device-authorization endpoint.
DEVICE_GRANT_TYPE
Device-code grant type (RFC 8628).
MAX_RESPONSE_BODY_BYTES
Maximum response body bytes accepted from device/poll/mint endpoints.
MINT_COPILOT_INTEGRATION_ID
MINT_EDITOR_PLUGIN_VERSION
MINT_EDITOR_VERSION
MINT_USER_AGENT
PROVIDER
Canonical storage / broker / model-prefix id.
REQUEST_TIMEOUT
Full request timeout for production device/poll/mint HTTP.
SCOPE
Least-privilege scope among common working values (community-observed).
SESSION_MINT_URL
Community-observed Copilot session-mint endpoint (pinned host+path).

Traits§

CopilotBrowser
Injectable browser opener (production uses open_browser).
CopilotCancel
Injectable cancellation signal for device-flow polling.
CopilotClock
Injectable clock (now + cancellable sleep) for deterministic poll tests.
CopilotHttp
Injectable HTTP surface so tests never touch the network.

Functions§

apply_slow_down
credentials_from_session
login
Production login entry (real network + system browser + auth.json).
login_with
Device start → user prompt → poll → mint → atomic persist.
mint_credentials
Build credentials after a successful mint (GitHub token → refresh).
mint_session_token
Exchange a long-lived GitHub user token for a short-lived Copilot session.
parse_device_code_response
parse_device_poll_response
parse_session_mint_response
poll_device_token
One poll against the token endpoint.
read_body_capped
Read a response body with a hard byte cap. Fail closed if exceeded.
refresh_token
Broker refresh: re-mint session from stored GitHub user token (no browser).
session_mint_request_headers
Headers attached only to the pinned session-mint request.
start_device_authorization
Start device authorization (POST device/code).
validate_device_endpoint
Accept only the exact pinned HTTPS github.com device endpoints.
validate_session_mint_endpoint
Accept only the pinned session-mint host+path (no query, no alternate host).
validate_verification_uri
Accept only the documented GitHub device verification destination: https://github.com/login/device optionally with a single user_code query (verification_uri_complete). Rejects userinfo, fragments, alternate ports, deceptive paths, and arbitrary query keys.
wait_for_device_authorization
Poll until authorized, denied, expired, cancelled, or deadline.

Type Aliases§

UserCodeHook