Skip to content

[CmdPal] Host-side OAuth redirect broker (Phase 2) - #49441

Draft
michaeljolley wants to merge 1 commit into
dev/mjolley/cmdpal-auth-flowfrom
dev/mjolley/cmdpal-auth-broker
Draft

[CmdPal] Host-side OAuth redirect broker (Phase 2)#49441
michaeljolley wants to merge 1 commit into
dev/mjolley/cmdpal-auth-flowfrom
dev/mjolley/cmdpal-auth-broker

Conversation

@michaeljolley

Copy link
Copy Markdown
Contributor

Summary

Phase 2 of the Command Palette built-in OAuth authorization flow: the host-side redirect broker. This is the second of a stack of 4 draft PRs and targets the Phase 1 branch (dev/mjolley/cmdpal-auth-flow, #49440).

Command Palette acts as a thin, hardened redirect broker. It allocates the redirect target, injects a cryptographically random state, opens the browser, captures the single redirect, validates state, and hands the raw response parameters back to the extension. Command Palette never sees the PKCE verifier and never stores third-party tokens; the Toolkit's OAuthClient performs the code exchange inside the extension's process.

What this adds

  • AuthBrokerService (Microsoft.CmdPal.UI.ViewModels/Auth): 256-bit state generation with single-use, fixed-time validation; parameter composition (appends redirect_uri and state); loopback and custom-scheme flows; timeout (default 60s, cap 300s), cancellation, concurrency, and teardown handling; non-blocking status via the host. Auth codes and tokens are never logged.
  • Loopback capture bound to 127.0.0.1 only via a raw TcpListener, so no HTTP.SYS URL ACL and no elevation are required inside the packaged process.
  • Custom scheme x-cmdpal://auth/callback routed by state from MainWindow.HandleLaunchNonUI, reusing the existing single-instance protocol activation wiring.
  • AppExtensionHost implements IExtensionHost2.RequestAuthorizationAsync, delegating to the broker.
  • Testability seams (IAuthBrokerPlatform, ILoopbackRedirectListenerFactory) with a default platform and a UI platform that re-foregrounds the window on capture.

Testing

  • Build: build.ps1 -Path src\modules\cmdpal -Platform x64 -Configuration Debug, exit code 0.
  • 14 new Auth unit tests (state generation, parameter composition and override, URL building, loopback happy path and state-mismatch and provider-error and timeout and cancel, cancel-all-flows, custom-scheme unknown-state and happy path and single-use), plus a real loopback TCP integration test.
  • All CmdPal *.UnitTests projects pass with zero failures.

Scope

Changes are limited to src/modules/cmdpal (CommandPalette.slnf). No XAML changed. Draft while the rest of the stack lands.

Add the Command Palette host broker that backs the built-in authorization
flow defined by the Phase 1 SDK contract. Command Palette acts as a thin,
hardened redirect broker: it allocates the redirect target, injects a
cryptographically random state, opens the browser, captures the single
redirect, validates state, and returns the raw response parameters to the
extension. It never sees the PKCE verifier and never stores third-party
tokens.

Details:
- AuthBrokerService: state generation and single-use validation, parameter
  composition, loopback and custom-scheme flows, timeout/cancel/concurrency
  handling, and non-blocking status via the host.
- Loopback listener bound to 127.0.0.1 only (no HTTP.SYS ACL, no elevation).
- Custom scheme x-cmdpal://auth/callback routed by state from
  MainWindow.HandleLaunchNonUI.
- AppExtensionHost implements IExtensionHost2.RequestAuthorizationAsync.
- Testability seams (platform, listener factory) with fakes; 14 Auth unit
  tests plus a real loopback TCP integration test.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 2ee31cb3-848f-43ba-ac48-f4e4485baa33
@github-actions github-actions Bot added the Product-Command Palette Refers to the Command Palette utility label Jul 21, 2026
@michaeljolley michaeljolley self-assigned this Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

0.102 Product-Command Palette Refers to the Command Palette utility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants