Repository navigation
feat(auth): sign in on Skia Desktop with a loopback WebAuthenticationBroker for the Oidc and Web providers (backport #3261) - #3264
Conversation
…Broker for the Oidc and Web providers Uno Platform has no WebAuthenticationBroker implementation on the Skia Desktop target: the built-in provider throws NotImplementedException, so AddOidc and AddWeb cannot complete an interactive sign-in there at all. This adds DesktopWebAuthenticationBrokerProvider (system browser plus a loopback HttpListener, loopback-only validation, one flow at a time, a static completion page, fragment relay, the broker's AuthenticationTimeout reported as a cancel with TimeoutErrorDetail) and registers it through Uno's ApiExtensibility registry from AddOidc/AddWeb on Windows, macOS and Linux only; the native brokers keep winning on Android, iOS, Mac Catalyst and WebAssembly, and an app that registers its own provider first keeps it. Extracted from #3169, which also changes the providers' refresh, cancellation and logout behaviour; this lands the platform gap on its own so it can ship first. The desktop broker runtime-test suite comes with it and is added to the runtime-tests host and the CI filter. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01Sn8GmJ41W3eBgT7866J3jV (cherry picked from commit cd2135d) # Conflicts: # Uno.Extensions.sln # doc/Learn/UpdatingExtensions.md
…Ms so its platform gate applies The suite is compiled out with `#if !__ANDROID__ && !__IOS__ && !__WASM__`, which only works when the project has those TFM flavours. With the library TFM list it was a single net10.0 build that every head loaded, so the loopback-listener tests ran inside the WebAssembly and mobile runtime-test hosts. Imports tfms-ui-winui-apps.props like the MSAL test project does. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01Sn8GmJ41W3eBgT7866J3jV (cherry picked from commit d3e1b11)
- specs/018: add "bindables" and "INDEI" to build/ci/cspell.json - specs/019 progress and specs/lessons.md: drop the trailing blank line (MD012) - Both fail the Docs Validations stage for every PR built against main Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01EouKGNoa82gPgVtVHaSAre (cherry picked from commit fd9e9e6) # Conflicts: # specs/019-mvux-selection-refresh/progress.md # specs/lessons.md
…ticationBroker
- TryRegister checks the registry first, returns true only when this broker is the registered provider, logs when another provider won, and runs after the hostBuilder null guard in AddWeb/AddWeb<T>/AddOidc
- OidcAuthenticationProvider re-reads the broker callback before every login/logout with AutoRedirectUri, so a port the broker had to forget is not kept from the Build() snapshot
- WebAuthenticatorBrowser maps the broker's status and TimeoutErrorDetail to BrowserResultType (Timeout, UserCancel, HttpError) instead of dropping them
- Broker: dual-family default-port probe, non-loopback requests rejected at the socket, per-flow Debug logs and a named launcher on Win32Exception, browser launch off the caller's thread, pooled form-post buffer, Cache-Control: no-store, protected ILogger constructor; file moved to match its namespace
- Tests: the static WebAuthenticationBroker driven end to end through a shared registered double (callback, success, timeout detail, second-flow rejection, cancellation, first-wins), a token-leak guard over every response and error path, the OIDC redirect red/green case and the browser-result mapping; [DoNotParallelize]
- Docs: no {State} reference, the Web provider's missing request binding stated, #if !WINDOWS and enableUnoLogging notes, the "registered after" case in UpdatingExtensions
- specs/020 progress with every finding and its status; two lessons on Uno's static-ctor provider snapshot and the cached per-type logger
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EouKGNoa82gPgVtVHaSAre
(cherry picked from commit 635ae43)
# Conflicts:
# specs/lessons.md
…esktop sign-out returns - OidcAuthenticationProvider.LogoutAsync passed no id_token_hint, so the identity provider would not redirect to PostLogoutRedirectUri and the desktop loopback broker waited out its five-minute timeout - Pass the cached id_token as LogoutRequest.IdTokenHint and the caller's CancellationToken to LogoutAsync - Red/green: Given_OidcAuthenticationProvider.When_Logout_Then_CachedIdTokenSentAsHint - Verified live against the Uno.Samples OIDC demo on macOS desktop with packages packed from this branch - Document the hint in HowTo-OidcAuthentication and the spec 020 progress note Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01EouKGNoa82gPgVtVHaSAre (cherry picked from commit 92c8c2d)
…bAuthenticationBroker - Broker: a failed browser launch no longer logs or rethrows the launcher's exception, whose message on Windows is the request URL (login_hint, and id_token_hint on sign-out); the log carries the launcher name and native error code, the caller gets a Win32Exception with a fixed message and no inner exception - WebAuthenticatorBrowser: the caller's cancellation propagates as OperationCanceledException so a cancelled sign-out takes the token-clearing exception path; the OIDC client's own BrowserOptions.Timeout maps to Timeout; NotImplementedException from Uno's stub broker names TryRegister/AddOidc; both CTSs disposed; ILogger injected; XML docs - Registration: the outcome of TryRegister is logged through the host's ILogger once built (IServiceInitialize) instead of at builder time, where no logger exists; the registration itself stays at builder time, ahead of any static-broker touch - Pooled form-post buffer cleared on return and sized to stay off the LOH; one protected constructor; dead negative platform list removed; TryRegister's returns states the early-touch limit - Tests (red/green): launch-failure token guard, OIDC-timeout-first, caller cancel, not-implemented mapping, registration outcome reaching a built host's logger once; guards for the no-id_token hint and logout-cancel propagation; EnsureRegistered proves the static broker bound to the double - Docs: the NotImplementedException symptom and the logging categories in both HowTo pages; the cross-platform OIDC behaviour changes in UpdatingExtensions - specs/020 second-round table; lesson on Process.Start exception messages Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01EouKGNoa82gPgVtVHaSAre (cherry picked from commit 51fc86f) # Conflicts: # specs/lessons.md
…ts registration - Rebuild the result from the callback's OriginalString, so the Web provider's StartsWith match survives a mixed-case host or an explicit default port - Resolve the registry after Register to confirm the loopback broker won, instead of assuming it - Move the default-port reset into a static helper - Docs: the registration line needs the Uno host and CoreLogLevel Information; a cancelled login now throws and keeps the stored tokens Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015tKeWCuqJ7QVyKcChvivDX (cherry picked from commit 7e79bf1)
- 020 is taken on main by the Uno.UI.Lottie reference - Add spec.md with the broker's design; record the PR review in progress.md - Point the id_token_hint note at #3169's own spec instead of main's 017 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015tKeWCuqJ7QVyKcChvivDX (cherry picked from commit 57a33be)
|
Cherry-pick of cd2135d has failed: Cherry-pick of fd9e9e6 has failed: Cherry-pick of 635ae43 has failed: Cherry-pick of 51fc86f has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally |
- Uno.Extensions.sln: keep only the auth test project and its folder (drop main's Navigation.Tests context) - UpdatingExtensions.md: move the Web/OIDC note into the 7.4 section; 7.4 has no 8.0 section - Test project: import tfms-ui-winui.props, since tfms-ui-winui-apps.props is 8.0-only - Drop the MVUX selection spec and lesson pulled in by the conflict resolution; that fix is not on 7.4 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015tKeWCuqJ7QVyKcChvivDX
|
Fixed the conflicts in 482e298:
Verified on macOS: the auth libraries and the test project build in Release ( |
GitHub Issue (If applicable): closes #
Extracted from #3169 so the platform gap can ship on its own. Two OIDC changes from #3169 landed here too, because desktop sign-in and sign-out needed them: cancellation propagation and
id_token_hint(see "Every platform" below). #3169 keeps the rest (refresh verdicts, honoringLogoutResult.IsError, per-flowstatein the Web provider, Web callback defaults) and rebases onto this.PR Type
What is the current behavior?
Uno Platform has no
WebAuthenticationBrokerimplementation on the Skia Desktop target (net10.0-desktop):WebAuthenticationBrokerProvider.skia.csthrowsNotImplementedException, and no desktop runtime package registers a replacement.AddOidc()routes every interactive step throughWebAuthenticatorBrowser→WebAuthenticationBroker, andAddWeb()uses the broker directly, so on Windows, macOS and Linux desktop both providers fail every sign-in: the provider logsError logging in: System.NotImplementedExceptionandLoginAsyncreturnsfalse. MSAL is unaffected because MSAL.NET brings its own system browser and loopback listener.Reproduced on Uno.Sdk 7.0.0-dev.77 / Uno.Extensions 8.0.0-dev.85 with the Uno.Samples OIDC extensions demo (unoplatform/Uno.Samples branch
dev/sb/oidc-extensions-demo), which has to ship an app-sideIBrowserto sign in on desktop at all.What is the new behavior?
Skia Desktop
DesktopWebAuthenticationBrokerProvider(inUno.Extensions.Authentication.WinUI): opens the request URI in the system browser and completes the flow from the first request to a loopbackHttpListenerbound to the callback URI. Loopback-only validation (URI and remote endpoint), one flow at a time (a second concurrent flow throwsInvalidOperationException),form_postbodies capped at 32 KB, staticno-storepages, relay of URL-fragment responses, and the broker'sAuthenticationTimeoutreported asUserCancelwithResponseErrorDetail = TimeoutErrorDetail(408). The result keeps the callback URI as the caller wrote it.LaunchBrowserAsyncisprotected virtualfor apps that want another browser or a private window. A failed browser launch never logs the request URL.AddOidc()andAddWeb()callDesktopWebAuthenticationBrokerProvider.TryRegister()off WinAppSDK. It registers the provider throughApiExtensibility.Register(typeof(IWebAuthenticationBrokerProvider), ...)only when the process runs on Windows, Linux or macOS; Android, iOS and the browser keep their native brokers (a runtime check, because the plain-TFM build of this assembly is what Skia mobile heads load). The registry is first-wins, so an app that registers its own provider beforeAddOidc/AddWebkeeps it, and apps that callWebAuthenticationBrokerdirectly can callTryRegister()themselves. The outcome is logged through the host's logger once the host is built.WebAuthenticationBroker.GetCurrentApplicationCallbackUri()on desktop returnshttp://localhost:{port}/authentication-callbackwith a port chosen once per process (free on IPv4 and IPv6 loopback, re-probed after a bind failure), orWinRTFeatureConfiguration.WebAuthenticationBroker.DefaultReturnUriwhen set. WithAutoRedirectUri, the OIDC provider follows that port on every flow.Every platform (OIDC provider)
WebAuthenticatorBrowserreports the broker's outcome as aBrowserResultType(Timeoutfor both the client's and the broker's timeout,UserCancel,HttpError) instead of aSuccesswith no response or anUnknownError.CancellationTokencancelled duringLoginAsync/LogoutAsyncnow propagates asOperationCanceledExceptionout ofIAuthenticationService. Before, a cancelledLoginAsyncreturnedfalseand, because the failed result was saved as an empty token set, also cleared the stored tokens; now it throws and leaves them alone. A cancelledLogoutAsyncstill clears the tokens. This applies on WinAppSDK too, where the WinUIEx branch shares the same catches.id_token_hint, which identity providers need before they redirect back toPostLogoutRedirectUri.Tests and docs
Uno.Extensions.Authentication.WinUI.Tests(runtime tests, gated to the desktop head, referenced from the runtime-tests host and added toRuntimeTestsFilter): 34 tests.Given_DesktopWebAuthenticationBrokerhas 20 cases; the rest are inGiven_DesktopWebAuthenticationBrokerRegistration,Given_WebAuthenticatorBrowserandGiven_OidcAuthenticationProvider.specs/021-desktop-web-auth-broker/(spec.md+progress.md).Verified locally on macOS (Skia desktop runtime-tests host, filter
Authentication.UI.Tests): 34 passed, 0 failed.Uno.Extensions.Authentication.WinUI,Uno.Extensions.Authentication.Oidc.WinUIand the test project build in Release with only the CS1591 warnings already onmain.PR Checklist
Screenshots Compare Test Runresults.Breaking changes: there are no binary or source breaks; the public surface is only additive. There is one runtime behavior change, described above: a cancelled
LoginAsyncnow throwsOperationCanceledExceptioninstead of returningfalse, and keeps the stored tokens. Apps that pass a cancellable token toLoginAsyncand don't catch will now see the exception. It is documented indoc/Learn/UpdatingExtensions.mdand was accepted in review.Other information
Not run locally: the Android, iOS, WebAssembly and WinAppSDK lanes (CI covers them). Windows Skia Desktop (http.sys
HttpListener) is not exercised by CI or by the local runs, which were on macOS. The provider is compiled out on WinAppSDK (#if !WINDOWS), where WinUIEx handles the activation.🤖 Generated with Claude Code
https://claude.ai/code/session_015tKeWCuqJ7QVyKcChvivDX
This is an automatic backport of pull request #3261 done by [Mergify](https://mergify.com).