Authentication
The Copilot SDK supports multiple authentication methods. Choose one based on your use case.Authentication methods
For BYOK, see
custom-providers.md.
Microsoft Entra ID
To use the built-in Microsoft Entra sign-in and token refresh, register your host application with the client. SetclientId to the Application (client) ID of your Entra app registration. You can pass an EntraAuthConfig instance or an array. Empty and whitespace-only values throw an InvalidArgumentException.
server.connect handshake. This registration is separate from the accounts.acquireEntraToken server RPC, which requests a token explicitly. If you set an Entra configuration and the runtime is too old to support connect, the SDK throws This runtime does not support Entra client configuration. instead of silently dropping the setting. Update the runtime in that case. Other authentication methods continue to work.
Network callbacks
Use thenetwork option to delegate the runtime’s proxy resolution and Kerberos Negotiate authentication to callbacks on the host. The Copilot runtime must support the network.setProvider RPC. If it does not, the client throws an exception at startup that asks you to update the runtime. Each callback receives the request type and a CancellationToken you can check for cancellation.
resolveProxy returns a PAC-style string such as PROXY proxy.example:8080; DIRECT, or DIRECT for a direct connection. Return null to let the runtime resolve the proxy itself. authenticateNegotiate returns a single-use base64 SPNEGO token without the Negotiate prefix, or null when no credentials are available. If a callback throws, the RPC fails and the runtime does not fall back to a direct connection. Validate the SPN before you issue credentials.
scope defaults to connection, which covers only requests from sessions this client created or resumed. runtime also covers shared background traffic, but only one connection at a time can hold this scope.
GitHub login (CLI)
If you are already logged in withcopilot or gh CLI, the SDK uses stored credentials by default.
OAuth GitHub App / PAT
Pass a user access token from OAuth, or a fine-grained PAT, togithub_token.
- Expected token prefixes:
gho_,ghu_,github_pat_ ghp_(classic PAT) is discouraged
github_token, use_logged_in_user is automatically set to false. To override explicitly:
github-token.md.
Both github_token and use_logged_in_user are only available in stdio mode. In TCP mode, the Copilot CLI must already be authenticated.
Mask host-generated secrets
If your host application obtains tokens dynamically, such as through MCP OAuth, register them with the Copilot CLI redaction filter. The CLI masks registered values in session logs and exports.onMcpAuthRequest. Call it explicitly after you obtain a token. The SDK does not persist the values or log them separately for this RPC.
Environment variables
If you pass a token via environment variables, the CLI auto-detects it using this priority order:COPILOT_GITHUB_TOKENGH_TOKENGITHUB_TOKEN
Authentication priority
The SDK resolves credentials in this order:github_token(explicitly provided)- Environment variable tokens (
COPILOT_GITHUB_TOKEN→GH_TOKEN→GITHUB_TOKEN) - OAuth credentials stored by CLI
- Credentials from
ghCLI
Disable automatic login
If you do not want to use stored credentials, setuse_logged_in_user to false.
When set to false, only the token you pass explicitly (github_token) is used for authentication. Environment variable tokens (COPILOT_GITHUB_TOKEN, GH_TOKEN, GITHUB_TOKEN) are ignored.
github_token, this is supported in stdio mode only. In TCP mode, the Copilot CLI must already be authenticated.
Check authentication status
You can read the result ofauth.getStatus.
Select an account for interactive login
EnumerateloginAccounts through the session RPC to get the stored identities you can reuse with a given provider. Each item’s label is for display, and active indicates whether the identity matches the current session’s active account. accountId is an opaque ID owned by the provider. Pass it to the login request as is, without parsing or modifying it.
mode: 'default' to reuse a stored identity with the provider’s normal behavior. Use mode: 'selectAccount' to explicitly show the provider’s account picker. In that case, don’t pass accountId. Existing calls such as begin(LoginProviderKind::ENTRA) continue to work.
For the latest updates, see the GitHub repository.