Search code examples
c#azureauthenticationblazorblazor-webassembly

How to fix auth error in Blazor WASM .NET 7 upgrade?


Ever since I updated my blazor wasm project which is hosted as a static site on azure to .Net 7, users have been getting redirected to "______.com/authentication/login-failed" even though the authentication is working properly. They can then navigate around the site with out issue, but not without seeing this error.

I can't reproduce this problem locally (only happens in azure production environment), and the only error I get is a 404 not found.

"Failed to load resource: the server responded with a status of 404 (The requested content does not exist.)"

Has anyone else experienced this, and hopefully found a solution?

I could roll back to .Net 6, but that had a ton of other authentication related problems, which .Net7 had fixed.


Solution

  • Adding the following to the client.csproj should fix it:

    <ItemGroup>
        <TrimmerRootAssembly Include="Microsoft.Authentication.WebAssembly.Msal" />
        <TrimmerRootAssembly Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" />
    </ItemGroup>
    

    source https://github.com/dotnet/aspnetcore/issues/44981