Skip to content

GitHubDeviceFlow

Namespace Nfty.Core.Publish.Community in assembly Nfty.Core.

public sealed class GitHubDeviceFlow

GitHub's OAuth device flow: no client secret, no browser callback. GitHubDeviceFlow.StartAsync() asks for a code to show, GitHubDeviceFlow.WaitForTokenAsync() polls until the person approves it on GitHub.

Constructors

GitHubDeviceFlow(HttpClient, string, Func<TimeSpan, CancellationToken, Task>?)

public GitHubDeviceFlow(HttpClient http, string clientId, Func<TimeSpan, CancellationToken, Task>? delay = null);

Parameters

  • http (HttpClient) - The client every request goes through.
  • clientId (string) - The OAuth app's client id (public).
  • delay (Func<TimeSpan, CancellationToken, Task>?) - Replaces Task.Delay between polls; tests inject one.

Methods

StartAsync(CancellationToken)

public Task<DeviceCode> StartAsync(CancellationToken cancellationToken);

Asks GitHub for a device code (scope public_repo).

Parameters

  • cancellationToken (CancellationToken) - Stops the request.

Returns. The device code and where the person enters it.

Exceptions

WaitForTokenAsync(DeviceCode, CancellationToken)

public Task<string> WaitForTokenAsync(DeviceCode code, CancellationToken cancellationToken);

Polls until the person approves, returning the access token.

Parameters

Returns. The access token GitHub issued.

Exceptions

  • GitHubAuthException - Canceled on GitHub, expired, or an unexpected answer.
  • OperationCanceledException - cancellationToken was canceled.