Skip to content

refactor: adopt Duende.IdentityModel.OidcClient for CLI auth (PROT-47)#9

Merged
BlakeHastings merged 1 commit into
mainfrom
feat/PROT-47-oidcclient
Jun 4, 2026
Merged

refactor: adopt Duende.IdentityModel.OidcClient for CLI auth (PROT-47)#9
BlakeHastings merged 1 commit into
mainfrom
feat/PROT-47-oidcclient

Conversation

@BlakeHastings
Copy link
Copy Markdown
Member

@BlakeHastings BlakeHastings commented Jun 3, 2026

Resolves PROT-47.

image

What

Replaces the hand-rolled OAuth code in src/Protostar.Cli/Auth/ with the certified Duende.IdentityModel.OidcClient library (Apache-2.0, OIDC-certified). Login, refresh, and userinfo now run through the registry's OIDC discovery document (/.well-known/openid-configuration) instead of hand-built endpoints and DTOs. The CLI owns far less protocol code.

Changes

  • Add Duende.IdentityModel.OidcClient 7.1.0.
  • New Auth/LoopbackBrowser.cs: a thin IBrowser hosting the one-shot loopback HttpListener on /callback (RFC 8252). The only protocol glue left.
  • New Auth/OidcClientFactory.cs: builds OidcClient against the registry authority's discovery doc.
  • LoginCommand: drives OidcClient.LoginAsync. Preserves --provider (front-channel identity_provider), --no-browser, and --timeout.
  • StatusCommand: refresh + userinfo via RefreshTokenAsync / GetUserInfoAsync.
  • RegistryClient: slimmed to just the /v1/meta API-compatibility check.
  • Removed the hand-rolled helpers: Pkce, LoopbackServer, the authorize-URL builder, and the token/userinfo DTOs.
  • Kept the file-based credential store (~/.protostar/credentials.json) and the /v1/meta compat check, exactly as before.

Headless ergonomics

  • Always echoes the sign-in URL, even when a browser is opened, so it is never hidden.
  • On a display-less Linux/Unix session (no DISPLAY/WAYLAND_DISPLAY) the launch attempt is skipped and the URL is printed, closing the gap where xdg-open "succeeds" with no browser shown.

The loopback redirect still requires the browser to share a host with the CLI; true remote-headless (device-code flow) would be a separate registry-side change.

Verification

  • dotnet build protostar.sln: clean, 0 warnings / 0 errors.
  • dotnet test: 21/21 pass (Reqnroll acceptance + credential-store), Windows.
  • Smoke-tested auth --help, auth status (offline), auth login --help, and auth login against an unreachable registry (fails fast on /v1/meta before opening a browser).

Replace the hand-rolled OAuth code with the certified Duende.IdentityModel.OidcClient
library, driving login, refresh, and userinfo through the registry's OIDC discovery
document instead of hand-built endpoints and DTOs.

- Add Duende.IdentityModel.OidcClient 7.1.0.
- Reduce the loopback listener to a thin IBrowser (LoopbackBrowser) and add an
  OidcClientFactory that targets the registry discovery doc.
- Drive login via OidcClient.LoginAsync (PKCE over a loopback redirect, RFC 8252);
  preserve the --provider shortcut via front-channel identity_provider, plus
  --no-browser and --timeout.
- Drive status refresh/userinfo via RefreshTokenAsync/GetUserInfoAsync.
- Slim RegistryClient to the /v1/meta compatibility check; keep the file-based
  credential store (~/.protostar/credentials.json).
- Remove the hand-rolled helpers: Pkce, LoopbackServer, the authorize-URL builder,
  and the token/userinfo DTOs.
- Harden headless support: always echo the sign-in URL and skip the browser launch
  on a display-less Linux/Unix session (no DISPLAY/WAYLAND_DISPLAY).
- Fix stale README wording (the store is the credential file, not the OS keychain).

Behavior is preserved; all acceptance scenarios stay green on Windows and Linux.
Copy link
Copy Markdown
Member

@ljones491 ljones491 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call not printing the start URL through Spectre

@BlakeHastings BlakeHastings merged commit 6db8a46 into main Jun 4, 2026
2 checks passed
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.

3 participants