Skip to content

Authentication Popup not closing for MSAL authentication extension #2692

Open

Description

@cosymon

Current behavior

When LoginAsync is called using the Authentication service, the popup doesn't send the token back to the main window, but instead sends it to a new page inside the popup.

Image

Image

After looking in the logs I found this error:
dbug: Uno.Extensions.Authentication.MSAL.MsalAuthenticationProvider[0]
LoginAsync - Error attempting to login [Error - Popup closed]

Expected behavior

The token is sent back to the main window, and the popup closes

How to reproduce it (as minimally and precisely as possible)

Add MSAL authentication following this tutorial

Environment

Target Framework (s): net9.0-browserwasm

Nuget Package (s): Uno.Extensions.Authentication.MSAL.WinUI

Package Version(s): 5.2.7

Affected platform(s):

  • iOS
  • macOS (AppKit)
  • Mac Catalyst
  • Android
  • WebAssembly
  • Windows
  • Skia (WPF)
  • Skia (GTK on Linux/macOS/Windows)
  • Skia (Linux Framebuffer)
  • Build tasks

Visual Studio:

  • 2019 (version: )
  • 2022 (version: )
  • Visual Studio Code (version: )
  • Rider Windows (version: )
  • Rider macOS (version: )

Additional Information

During troubleshooting, I changed the target framework to net8.0-browserwasm, and it worked as intended

Activity

  1. added
    kind/bug
    triage/untriaged
    on Feb 12, 2025
  2. VincentH-Net commented on May 26, 2025

    @VincentH-Net

    I have the same issue, .NET SDK 9.0.300 and Uno SDK 6.0.96, target net9.0-browserwasm, on opening the login windows this exception occurs:

    fail: Uno.UI.Dispatching.NativeDispatcher[0]
          NativeDispatcher unhandled exception
    System.Exception: Popup closed
       at Uno.Extensions.Authentication.MSAL.MsalAuthenticationProvider.InternalLoginAsync(IDispatcher dispatcher, IDictionary`2 credentials, CancellationToken cancellationToken)
       at Uno.Extensions.Authentication.BaseAuthenticationProvider.LoginAsync(IDispatcher dispatcher, IDictionary`2 credentials, CancellationToken cancellationToken)
       at Uno.Extensions.Authentication.AuthenticationService.LoginAsync(IDispatcher dispatcher, IDictionary`2 credentials, String provider, Nullable`1 cancellationToken)

    After selecting an account the login popup does not close and the app appears in the login popup

    When changing the target to net8.0-browserwasm; it works.

    This is a blocking issue for upgrading my app to .NET 9, which prevents me from using Hot Design (because Hot Reload only works on .NET 9)

  3. added and removed
    triage/untriaged
    on May 27, 2025
  4. added theissue type on May 27, 2025
  5. erikvilima commented on May 28, 2025

    @erikvilima
    Contributor

    @kazo0 I'm trying to repro this issue but I'm getting something totally different. When the msal popup opens and I try to login I get an error message about redirect uri. It may be something wrong with my setup.

    This is my repro app.

    nativeExtensions2692.zip

  6. erikvilima commented on May 29, 2025

    @erikvilima
    Contributor

    @kazo0 I'm trying to repro this issue but I'm getting something totally different. When the msal popup opens and I try to login I get an error message about redirect uri. It may be something wrong with my setup.

    This is my repro app.

    nativeExtensions2692.zip

    I can repro the issue. We are investigating the cause.

  7. trydalch commented on Jun 3, 2025

    @trydalch

    Hi @erikvilima. Thanks for looking at this. Do you have any update?

  8. self-assigned this
    on Jun 6, 2025
  9. kazo0 commented on Jun 6, 2025

    @kazo0
    Contributor

    @trydalch

    Still investigating, it seems related to the Cross-Origin-Opener-Policy and multi-threading in net9 maybe?

    Relevant:

    If we perhaps play around with some of the msbuild properties mentioned in the links above, testing to see if those have any effect

  10. jeromelaban commented on Jun 6, 2025

    @jeromelaban
    Member

    At present time dotnet/runtime#109937 forces COOP, which breaks any kind of cross site behavior. There are multiple ways around it, until this issue is fixed:

    • Use an uno "server" project which will host the website on its own, and will not have COOP enabled. Wasm Debugging may not work as intended in that context, though, but starting it without the debugger will work and hot design will work properly.
    • Use dotnet serve on the CLI, but in this case, there's no support for hot design, nor debugging.
  11. erikvilima commented on Jun 9, 2025

    @erikvilima
    Contributor
  12. kazo0 commented on Jun 9, 2025

    @kazo0
    Contributor

    FYI @cosymon / @VincentH-Net / @trydalch See Jerome's comment

    I have validated with the sample app that @erikvilima has provided that running the app via dotnet serve from the wwwroot folder in the bin/ that it is working with that method

    It also works by using a Server project and launching the app through that. For this, I create a new Uno app through the Wizard and selected the Server project in Features:

    Image

    and ran a dotnet publish for the Server project and launched from the Release/bin/publish/wwroot folder

    I will keep this issue to track the documentation change we should be adding immediately to call this out in the Extensions MSAL docs and the general MSAL Uno docs

  13. carldebilly commented on Jun 9, 2025

    @carldebilly
    Member

    The publish is not required to run the project locally in DEV...

  14. VincentH-Net commented on Jun 10, 2025

    @VincentH-Net

    Thanks for all the investigations @erikvilima ; do I understand correctly that:

    So the issue is a blocker for debugging, and the resolution discussed above is a workaround that also blocks debugging, then we are left with no debugging for wasm apps that use the authentication extension.

    The .NET 9 defect dotnet/runtime#109937 which causes this is open since Nov 2024, and we are now close to .NET 10. This does not inspire confidence that Microsoft will fix this in a reasonable time frame.

    Q: Is there any other workaround conceivable (e.g. in the authorization extension) that does give us debugging authenticated wasm apps? Is the issue fixed in .NET 10 perhaps?

    Thanks!

  15. VincentH-Net commented on Aug 12, 2025

    @VincentH-Net

    Q: Is there any other workaround conceivable (e.g. in the authorization extension) that does give us debugging authenticated wasm apps? Is the issue fixed in .NET 10 perhaps?

    @kazo0 any plans / tips to unblock?

    No debugging on .NET 9 means production wasm apps that use the auth extension are stuck on .NET 8; mine has been for months.

  16. kazo0 commented on Aug 15, 2025

    @kazo0
    Contributor

    FYI @VincentH-Net / @cosymon it looks like the blocking issue was just recently fixed in .NET 10! I would expect the fix to be available in an upcoming RC1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/authenticationkind/bug

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions