Skip to content

Add GitHub credential provider (OAuth device flow)#6

Merged
StuartMeeks merged 1 commit into
mainfrom
feature/github-provider
Jun 20, 2026
Merged

Add GitHub credential provider (OAuth device flow)#6
StuartMeeks merged 1 commit into
mainfrom
feature/github-provider

Conversation

@StuartMeeks

Copy link
Copy Markdown
Owner

What

Adds NextIteration.SpectreConsole.Auth.Providers.GitHub — a credential provider for the framework, using the OAuth device flow, the same flow gh auth login uses by default. GitHub is far more relatable than the existing niche providers, making the repo a better teaching sample for "how do I write a provider."

Auth model

The collector runs the device flow end to end:

  1. Prompts for the GitHub host (default github.com), the OAuth App client id, and the requested scopes (default repo read:org).
  2. Requests a device/user code (POST {host}/login/device/code).
  3. Shows the user code + verification URL, then polls POST {host}/login/oauth/access_token honouring the server interval, the slow_down back-off, and authorization_pending, until the user authorises (or the code expires).
  4. Validates and enriches via GET {api}/user ("authenticated as X").

The OAuth App client id is prompted (the user brings their own app), so nothing needs to be registered or embedded in the repo. The auth service is a pass-through for classic non-expiring tokens; for apps that issue expiring tokens it refreshes via grant_type=refresh_token before use.

Scope of changes

  • New source project src/...GitHub/: GitHubCredential, GitHubToken, DTOs, GitHubCredentialCollector, GitHubAuthenticationService, GitHubCredentialSummaryProvider, ServiceCollectionExtensions, csproj (dual-target net8.0/net10.0), README, icon.
  • New test project tests/...GitHub.Tests/: 49 xUnit tests. A sequenced StubHttpClientFactory plus an injected clock/delay cover the device-code, polling (pending / slow_down / denied / timeout), user-enrichment, and refresh paths without sleeping on real intervals.
  • Repo wiring: solution, CI (github-v* tag trigger, pack step, publish case + if), top-level README (providers table + DI snippet), CHANGELOG (GitHub 0.1.0), RELEASING (tag table), and a matching design SVG + package icon.
  • Configurable host derives the Enterprise Server web (https://{host}/) and REST (https://{host}/api/v3/) base URLs.

Known limitation

A refreshed access token is not written back to the keystore in this version (the core ICredentialManager exposes no update API). Documented in the package README; consumers should cache the returned token for its lifetime.

Verification

  • dotnet build -c Release — clean, 0 warnings (both target frameworks).
  • dotnet test -c Release — all suites green (Adobe, Airtable, GitHub 49, SoftwareOne).
  • dotnet pack.nupkg/.snupkg build with icon.png + README.md packed for both TFMs.

Adds NextIteration.SpectreConsole.Auth.Providers.GitHub, a credential
provider whose collector runs the OAuth device flow — the same flow the
GitHub CLI uses by default. It prompts for the GitHub host, OAuth App
client id, and scopes; requests a device/user code; polls the token
endpoint (honouring interval, slow_down, and authorization_pending);
then validates and enriches the credential via GET /user.

- GitHubCredential / GitHubToken / GitHubAuthenticationService /
  GitHubCredentialCollector / GitHubCredentialSummaryProvider, plus the
  AddGitHubAuthProvider DI extension.
- Configurable host: defaults to github.com; an Enterprise Server host
  derives the matching web and /api/v3 base URLs.
- Token refresh for OAuth Apps that issue expiring tokens; classic
  non-expiring tokens pass straight through.
- Full xUnit suite (49 tests) with a sequenced HTTP stub and injected
  clock/delay so the polling and refresh paths are covered without sleeping.
- Wires the project into the solution, CI (github-v* tag, pack, publish),
  the top-level README, CHANGELOG, RELEASING, and a matching package icon.
@StuartMeeks StuartMeeks merged commit c873081 into main Jun 20, 2026
2 checks passed
@StuartMeeks StuartMeeks deleted the feature/github-provider branch June 20, 2026 02:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant