Skip to content

CopilotProvider

Namespace: E2E.OAuth

public sealed class CopilotProvider : IOAuthProvider

GitHub Copilot. The Copilot API accepts a GitHub sign-in as the bearer, so the login is either the token the GitHub CLI already holds or GitHub’s device flow for an OAuth App you register. GitHub user tokens do not expire; a 401 means signing in again.

Inheritance: object

Implements: IOAuthProvider

View source

CopilotProvider(HttpClient?, string?, Func<string?, CancellationToken, Task<string?>>?)

Section titled “CopilotProvider(HttpClient?, string?, Func<string?, CancellationToken, Task<string?>>?)”
public CopilotProvider(HttpClient? http = null, string? githubUrl = null, Func<string?, CancellationToken, Task<string?>>? githubCliToken = null)

Parameters

Name Type Description
http HttpClient Sends the login’s own requests. Unset, a shared client.
githubUrl string Test seam: the GitHub host the device flow talks to.
githubCliToken Func<string, CancellationToken, Task<string>> Test seam: how the GitHub CLI’s token is read for a host.

View source

public const string ApiUrl = "https://api.githubcopilot.com"

Value: string

View source

public string Id { get; }

The id in the credentials file and on the command line: openai, github-copilot, opencode-console, spacexai.

Value: string

View source

public string Name { get; }

The vendor’s name for messages.

Value: string

View source

public static string BaseUrl(string? enterpriseUrl)

The Copilot API base for github.com or an enterprise host.

Parameters

Name Type Description
enterpriseUrl string

Returns: string

View source

public static string EnterpriseHost(string value)

The bare host of a GitHub Enterprise URL. The bearer token goes to a host derived from it, so anything but a plain hostname is refused rather than guessed at.

Parameters

Name Type Description
value string

Returns: string

View source

ListModelsAsync(HttpClient, CancellationToken)

Section titled “ListModelsAsync(HttpClient, CancellationToken)”
public Task<IReadOnlyList<SubscriptionModel>> ListModelsAsync(HttpClient http, CancellationToken cancellationToken)

The chat models the plan serves. A model it cannot call is listed but marked: one the plan has not enabled, or one Copilot serves only over APIs these clients do not speak.

Parameters

Name Type Description
http HttpClient
cancellationToken CancellationToken

Returns: Task<IReadOnlyList<SubscriptionModel>>

View source

LoginAsync(OAuthLoginCallbacks, OAuthLoginOptions, CancellationToken)

Section titled “LoginAsync(OAuthLoginCallbacks, OAuthLoginOptions, CancellationToken)”
public Task<OAuthCredentials> LoginAsync(OAuthLoginCallbacks callbacks, OAuthLoginOptions options, CancellationToken cancellationToken)

Parameters

Name Type Description
callbacks OAuthLoginCallbacks
options OAuthLoginOptions
cancellationToken CancellationToken

Returns: Task<OAuthCredentials>

View source

PrepareAsync(HttpRequestMessage, OAuthCredentials, CancellationToken)

Section titled “PrepareAsync(HttpRequestMessage, OAuthCredentials, CancellationToken)”
public Task PrepareAsync(HttpRequestMessage request, OAuthCredentials credentials, CancellationToken cancellationToken)

Routes an enterprise login at its host and adds Copilot’s headers: who initiated the turn, and that images are present.

Parameters

Name Type Description
request HttpRequestMessage
credentials OAuthCredentials
cancellationToken CancellationToken

Returns: Task

View source

RefreshAsync(OAuthCredentials, CancellationToken)

Section titled “RefreshAsync(OAuthCredentials, CancellationToken)”
public Task<OAuthCredentials> RefreshAsync(OAuthCredentials credentials, CancellationToken cancellationToken)

Renews the credentials, or throws LoginRequired when the user has to sign in again.

Parameters

Name Type Description
credentials OAuthCredentials
cancellationToken CancellationToken

Returns: Task<OAuthCredentials>

View source