You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Auth][Desktop/Skia] Add support for WebAuthenticationBroker for OIDC/Web #2640
Why would you want to remove the dependency on Web Auth Broker? It's a robust mechanism and less proprietary than the IBrowser interface. In the latest WinUI, Microsoft introduced a new OAuth2Manager in the latest version of WinAppSdk (1.7), so we should consider aligning with it.
Actually, I did something slightly different: instead of customizing the IBrowser interface specific to EntityModel.OidcClient (now renamed Duende.IdentityModel.OidcClient), I implemented a custom WebAuthenticationBroker within Uno (leveraging Uno's built-in API extensibility mechanisms) and used the AutoRedirectUri feature to correctly resolve the URI from the browser.
#if HAS_UNO_SKIAusingSystem.Diagnostics;usingSystem.Runtime.InteropServices;usingWindows.Security.Authentication.Web;usingUno.AuthenticationBroker;usingUno.Foundation.Extensibility;usingYllibed.HttpServer;usingYllibed.HttpServer.Handlers;[assembly:ApiExtension(typeof(IWebAuthenticationBrokerProvider),typeof(SystemBrowserAuthBroker))]namespaceMyApp.Services.Auth;publicsealedclassSystemBrowserAuthBroker:IWebAuthenticationBrokerProvider{privateServer?_server;privateUri?_serverRootUri;publicUriGetCurrentApplicationCallbackUri(){returnnewUri(EnsureServerStarted().RootUri,"/auth-callback");}publicasyncTask<WebAuthenticationResult>AuthenticateAsync(WebAuthenticationOptionsoptions,UrirequestUri,UricallbackUri,CancellationTokenct){if(options.HasFlag(WebAuthenticationOptions.SilentMode)){thrownewNotSupportedException("SilentMode is not supported by this broker.");}if(options.HasFlag(WebAuthenticationOptions.UseTitle)){thrownewNotSupportedException("UseTitle is not supported by this broker.");}if(options.HasFlag(WebAuthenticationOptions.UseHttpPost)){thrownewNotSupportedException("UseHttpPost is not supported by this broker.");}if(options.HasFlag(WebAuthenticationOptions.UseCorporateNetwork)){thrownewNotSupportedException("UseCorporateNetwork is not supported by this broker.");}var(server, _)=EnsureServerStarted();varauthCallbackHandler=newAuthCallbackHandler(callbackUri);using(server.RegisterHandler(authCallbackHandler)){OpenBrowser(requestUri);returnawaitauthCallbackHandler.WaitForCallbackAsync();}}private(ServerServer,UriRootUri)EnsureServerStarted(){if(_serverisnull||_serverRootUriisnull){_server=newServer();(_serverRootUri,_)=_server.Start();}return(_server,_serverRootUri);}publicstaticvoidOpenBrowser(Uriuri){varurl=uri.AbsoluteUri;try{Process.Start(url);}catch{// hack because of this: https://github.com/dotnet/corefx/issues/10361if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)){url=url.Replace("&","^&");Process.Start(newProcessStartInfo("cmd",$"/c start {url}"){CreateNoWindow=true});}elseif(RuntimeInformation.IsOSPlatform(OSPlatform.Linux)){Process.Start("xdg-open",url);}elseif(RuntimeInformation.IsOSPlatform(OSPlatform.OSX)||RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD)){Process.Start("open",url);}else{throw;}}}privatesealedclassAuthCallbackHandler(UricallbackUri):IHttpHandler{privatereadonlyTaskCompletionSource<WebAuthenticationResult>_tcs=new();publicTaskHandleRequest(CancellationTokenct,IHttpServerRequestrequest,stringrelativePath){if(request.Url.AbsolutePath.StartsWith(callbackUri.AbsolutePath,StringComparison.OrdinalIgnoreCase)){varresult=newWebAuthenticationResult(request.Url.OriginalString,200,WebAuthenticationStatus.Success);_tcs.TrySetResult(result);request.SetResponse("text/plain","Auth completed - you can close this browser now.");}returnTask.CompletedTask;}publicTask<WebAuthenticationResult>WaitForCallbackAsync(){return_tcs.Task;}}}
#endif
changed the title [-][Auth] Use custom IBrowser for OIDC/MSAL[/-][+][Auth][Desktop/Skia] Add support for WenAuthenticationBroker for OIDC/MSAL[/+]on Jul 21, 2025
changed the title [-][Auth][Desktop/Skia] Add support for WenAuthenticationBroker for OIDC/MSAL[/-][+][Auth][Desktop/Skia] Add support for WebAuthenticationBroker for OIDC/MSAL[/+]on Jul 21, 2025
@carldebilly do you see a chance that this could get https available and that we could pass in the relative path dynamically?
that would allow us to have multiple providers registred. Like if we would have Amazon and like I am currently Etsy, it would be best to provide that like for the http handler in appsettings as "Url" = "/signin-amazon" or "Url" = "/callback-etsy" 🤔
or does the "AuthCallbackHandler" in some other way get available (currently private?) to allow us configuring that CallbackUri?
OidcAuthenticationProvider likely still fails on Desktop/Skia
Even though the IdentityModel.OidcClient namespace now matches the rebranded Duende.IdentityModel.OidcClient in the latest Uno.Extensions, I would still expect Desktop/Skia to fail because OidcAuthenticationProvider relies on: WebAuthenticationBroker.GetCurrentApplicationCallbackUri()
…but WebAuthenticationBroker isn’t implemented on Desktop, and we also don’t have the usual csproj/Win32-manifest style “registered callback URI” support you’d know from classic WinForms/WPF frameworks. 🫤
WebAuthenticationProvider hard-depends on WebAuthenticationBroker.AuthenticateAsyncUno.Extensions.Authentication.UI’s WebAuthenticationProvider is strongly coupled to: WebAuthenticationBroker.AuthenticateAsync(...)
WebAuthenticationBroker ignores IServiceCollection registrations because WebAuthenticationBroker uses ApiExtensibility.CreateInstance(null, out _authenticationBrokerProvider);. So even if an implementation of IWebAuthenticationBrokerProvider exists in DI, it won’t be used
ApiExtensibilityAttribute doesn’t support ctor args (and null likely blocks it anyway)
The [ApiExtensibility(...)] mechanism doesn’t allow passing ctor arguments, and the explicit null passed into CreateInstance(...) appears to prevent any pathway for DI-based creation.
It’s possible to integrate cleanly, with (or without) support of IOptions<T>, comes with tests, and includes a dedicated integration path for WebAuthenticationResult - which WebAuthenticationProvider currently expects from WebAuthenticationBroker.
But due to (4) + (5), there’s currently no workable way to integrate such a provider into the existing Uno.Extensions.Authentication flow on Desktop/Skia.
@Jen-Uno FYI - Maybe you could take a look if there is some progress available for this? Merging the PR to allow a DI version of the IWebAuthenticationBrokerProvider in the WebAuthenticationProvider would from my POV be the lowest effort option to have a working Desktop Auth Workaround until someone comes up with a other / better solution 👍
Re-scoping this issue to OIDC/Web — dropping MSAL from its scope.
MSAL no longer needs a WebAuthenticationBroker on Desktop/Skia:
MsalAuthenticationProvider never uses the WAB on desktop targets — MSAL.NET drives interactive sign-in itself via the system browser + loopback redirect (http://localhost). The provider's only WAB call (WithWebRedirectUri()) is gated to WebAssembly, where the broker has a working implementation.
OidcAuthenticationProvider drives its browser through WebAuthenticatorBrowser, which wraps WebAuthenticationBroker.AuthenticateAsync.
The generic WebAuthenticationProvider (AddWeb) calls WebAuthenticationBroker.AuthenticateAsync directly.
Uno's default Skia broker (WebAuthenticationBrokerProvider.skia.cs) throws NotImplementedException, so both providers are non-functional on Desktop/Skia unless the app registers a custom IWebAuthenticationBrokerProvider (like @carldebilly's SystemBrowserAuthBroker above).
Open design question for whoever picks this up: a default in-Uno WAB implementation (e.g. the lightweight-HTTP-server approach above) vs. an OidcClient IBrowser implementation in this repo vs. aligning with WinAppSdk 1.7's OAuth2Manager.
Separate note: MSAL's WAM broker (WithBroker) is currently only wired on the WinAppSdk head; enabling WAM SSO for desktop-TFM apps running on Windows would be an MSAL enhancement independent of the WebAuthenticationBroker.
changed the title [-][Auth][Desktop/Skia] Add support for WebAuthenticationBroker for OIDC/MSAL[/-][+][Auth][Desktop/Skia] Add support for WebAuthenticationBroker for OIDC/Web[/+]on Aug 12, 2026
Activity
kazo0 commentedon Dec 9, 2024
Poking @carldebilly / @nickrandolph for anymore info that we need for this one.
Doing this will allow us to no longer rely on the
WebAuthenticationBroker, correct?carldebilly commentedon Dec 9, 2024
Why would you want to remove the dependency on Web Auth Broker? It's a robust mechanism and less proprietary than the IBrowser interface. In the latest WinUI, Microsoft introduced a new
OAuth2Managerin the latest version of WinAppSdk (1.7), so we should consider aligning with it.Actually, I did something slightly different: instead of customizing the IBrowser interface specific to EntityModel.OidcClient (now renamed
Duende.IdentityModel.OidcClient), I implemented a custom WebAuthenticationBroker within Uno (leveraging Uno's built-in API extensibility mechanisms) and used the AutoRedirectUri feature to correctly resolve the URI from the browser.The missing piece is the custom Web Authentication Broker (WAB), which uses my "new" http server. This server is extremely lightweight, has no dependencies, and is far easier to use than Kestrel. Check it out here: https://www.nuget.org/packages/Yllibed.HttpServer/1.0.0-dev.10.ge2ac37743f#readme-body-tab
Code:
[-][Auth] Use custom IBrowser for OIDC/MSAL[/-][+][Auth][Desktop/Skia] Add support for WenAuthenticationBroker for OIDC/MSAL[/+][-][Auth][Desktop/Skia] Add support for WenAuthenticationBroker for OIDC/MSAL[/-][+][Auth][Desktop/Skia] Add support for WebAuthenticationBroker for OIDC/MSAL[/+]DevTKSS commentedon Aug 2, 2025
@carldebilly do you see a chance that this could get https available and that we could pass in the relative path dynamically?
that would allow us to have multiple providers registred. Like if we would have Amazon and like I am currently Etsy, it would be best to provide that like for the http handler in appsettings as
"Url" = "/signin-amazon"or"Url" = "/callback-etsy"🤔or does the "AuthCallbackHandler" in some other way get available (currently private?) to allow us configuring that CallbackUri?
kazo0 commentedon Aug 11, 2025
@carldebilly should your
SystemBrowserAuthBrokerbe defined and registered via APIExtension inside of the Uno Extensions Auth library itself?Would this be a temporary way of handling auth until unoplatform/uno#19787 is implemented?
I'm not sure where/how to use this IWebAuthenticationBrokerProvider implementation when using Uno Auth MSAL/OIDC Extensions
WebAuthenticationBrokeruno#18585 as a duplicate of this issueDevTKSS commentedon Jan 12, 2026
@kazo0
OidcAuthenticationProvider likely still fails on Desktop/Skia
Even though the
IdentityModel.OidcClientnamespace now matches the rebrandedDuende.IdentityModel.OidcClientin the latestUno.Extensions, I would still expect Desktop/Skia to fail becauseOidcAuthenticationProviderrelies on:WebAuthenticationBroker.GetCurrentApplicationCallbackUri()uno.extensions/src/Uno.Extensions.Authentication.Oidc/OidcAuthenticationProvider.cs
Lines 16 to 28 in 5235975
…but
WebAuthenticationBrokerisn’t implemented on Desktop, and we also don’t have the usual csproj/Win32-manifest style “registered callback URI” support you’d know from classic WinForms/WPF frameworks. 🫤WebAuthenticationProvider hard-depends on WebAuthenticationBroker.AuthenticateAsync
Uno.Extensions.Authentication.UI’sWebAuthenticationProvideris strongly coupled to:WebAuthenticationBroker.AuthenticateAsync(...)uno.extensions/src/Uno.Extensions.Authentication.UI/Web/WebAuthenticationProvider.cs
Lines 86 to 93 in 5235975
IWebAuthenticationBrokerProvider can’t be DI-resolved due to ApiExtensibility.CreateInstance
I tried registering my own
IWebAuthenticationBrokerProviderviaIServiceCollection, but it can’t be resolvedApiExtensibility.CreateInstance(...)bypasses DI entirely.So any Implementation of
WebAuthenticationBrokerProviderthat needsIOptions<AuthOptions>or a dedicated service (e.g., anOAuthCallbackHandler). This could be workaround'ed by acceptingIWebAuthenticationBrowserProvidervia optional ctor argument as suggested in my PR on the Uno.Extensions Repo: feat(WebAuthenticationProvider): Allow providing IWebAuthenticationBrokerProvider via DI parameters #2890WebAuthenticationBroker ignores IServiceCollection registrations because
WebAuthenticationBrokerusesApiExtensibility.CreateInstance(null, out _authenticationBrokerProvider);. So even if an implementation ofIWebAuthenticationBrokerProviderexists in DI, it won’t be usedApiExtensibilityAttribute doesn’t support ctor args (and null likely blocks it anyway)
The
[ApiExtensibility(...)]mechanism doesn’t allow passing ctor arguments, and the explicitnullpassed intoCreateInstance(...)appears to prevent any pathway for DI-based creation.https://github.com/unoplatform/uno/blob/f5cc992e78fcac760f4a9dbde445306eea5aaff7/src/Uno.Foundation/Extensibility/ApiExtensibility.cs#L71-L96
While it would be really cool and straight forward, the Walkthrought for Web Auth in the Docs is false stating that it will be using
WebViewwhich is not the case! [WebView] [Auth] Wrong Docs title suggesting to be able to use Web Auth provider with WebView #2972Why I’m bringing this up (practical integration angle)
I tried the above with the
AuthCallbackHandlerfrom my PR againstcarldebilly/Yllibed.HttpServer:This handler could act (at least in Development) as the local OAuth callback backend for Uno apps eventually even for the currently not WebView using Web Auth as stated in the Docs
It’s possible to integrate cleanly, with (or without) support of
IOptions<T>, comes with tests, and includes a dedicated integration path forWebAuthenticationResult- whichWebAuthenticationProvidercurrently expects fromWebAuthenticationBroker.But due to (4) + (5), there’s currently no workable way to integrate such a provider into the existing
Uno.Extensions.Authenticationflow on Desktop/Skia.@Jen-Uno FYI - Maybe you could take a look if there is some progress available for this? Merging the PR to allow a DI version of the
IWebAuthenticationBrokerProviderin theWebAuthenticationProviderwould from my POV be the lowest effort option to have a working Desktop Auth Workaround until someone comes up with a other / better solution 👍feat: Add SkiaWebAuthenticationBrokerProvider for desktop OIDC support
kazo0 commentedon Aug 12, 2026
Re-scoping this issue to OIDC/Web — dropping MSAL from its scope.
MSAL no longer needs a
WebAuthenticationBrokeron Desktop/Skia:MsalAuthenticationProvidernever uses the WAB on desktop targets — MSAL.NET drives interactive sign-in itself via the system browser + loopback redirect (http://localhost). The provider's only WAB call (WithWebRedirectUri()) is gated to WebAssembly, where the broker has a working implementation.Uno.UI.MSALflavor deployed underUnoFeatures=SkiaRenderer), interactive MSAL sign-in was validated live on Skia-Desktop (system browser + loopback), Skia-Android (custom tab), and Skia-WASM (popup viaWasmWebUi).What remains — and why this issue stays open:
OidcAuthenticationProviderdrives its browser throughWebAuthenticatorBrowser, which wrapsWebAuthenticationBroker.AuthenticateAsync.WebAuthenticationProvider(AddWeb) callsWebAuthenticationBroker.AuthenticateAsyncdirectly.WebAuthenticationBrokerProvider.skia.cs) throwsNotImplementedException, so both providers are non-functional on Desktop/Skia unless the app registers a customIWebAuthenticationBrokerProvider(like @carldebilly'sSystemBrowserAuthBrokerabove).Open design question for whoever picks this up: a default in-Uno WAB implementation (e.g. the lightweight-HTTP-server approach above) vs. an OidcClient
IBrowserimplementation in this repo vs. aligning with WinAppSdk 1.7'sOAuth2Manager.Separate note: MSAL's WAM broker (
WithBroker) is currently only wired on the WinAppSdk head; enabling WAM SSO for desktop-TFM apps running on Windows would be an MSAL enhancement independent of the WebAuthenticationBroker.[-][Auth][Desktop/Skia] Add support for WebAuthenticationBroker for OIDC/MSAL[/-][+][Auth][Desktop/Skia] Add support for WebAuthenticationBroker for OIDC/Web[/+]