Skip to main content

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. Set clientId 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.
You can also pass an array:
The SDK sends the client ID to the runtime during the 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 the network 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 with copilot 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, to github_token.
  • Expected token prefixes: gho_, ghu_, github_pat_
  • ghp_ (classic PAT) is discouraged
When you set github_token, use_logged_in_user is automatically set to false. To override explicitly:
For details, see 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.
This call is separate from obtaining and passing tokens with 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:
  1. COPILOT_GITHUB_TOKEN
  2. GH_TOKEN
  3. GITHUB_TOKEN
In TCP mode, set environment variables on the CLI server side.

Authentication priority

The SDK resolves credentials in this order:
  1. github_token (explicitly provided)
  2. Environment variable tokens (COPILOT_GITHUB_TOKEN → GH_TOKEN → GITHUB_TOKEN)
  3. OAuth credentials stored by CLI
  4. Credentials from gh CLI

Disable automatic login

If you do not want to use stored credentials, set use_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.
As with 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 of auth.getStatus.

Select an account for interactive login

Enumerate loginAccounts 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.
Use 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.
Last modified on November 9, 2026