GitHubDeviceFlow¶
Namespace Nfty.Core.Publish.Community in assembly Nfty.Core.
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>?) - ReplacesTask.Delaybetween polls; tests inject one.
Methods¶
StartAsync(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
GitHubAuthException- GitHub refused or answered in a way nfty doesn't understand.
WaitForTokenAsync(DeviceCode, CancellationToken)¶
Polls until the person approves, returning the access token.
Parameters
code(DeviceCode) - The device code fromGitHubDeviceFlow.StartAsync().cancellationToken(CancellationToken) - Stops the polling.
Returns. The access token GitHub issued.
Exceptions
GitHubAuthException- Canceled on GitHub, expired, or an unexpected answer.OperationCanceledException-cancellationTokenwas canceled.