DEV Community

Cover image for Fix Blazor WebAssembly authorization bug on Azure
Emanuele Bartolesi
Emanuele Bartolesi

Posted on

Fix Blazor WebAssembly authorization bug on Azure

Today I wasted more or less 2 hours for a stupid bug on a Blazor WASM hosted on ASP.NET Core app.
As always, it works on my machine.

Image description

I have created an application secure with Azure AD (and roles) and I use it for debugging for one month, without any issues.
When I tried to deployed everything on our test application on Azure, after the login, I obtained always the error:

login.microsoftonline.com/common/oauth2/v2.0/token:1 Failed to load resource: the server responded with a status of 400 (Bad Request)
Enter fullscreen mode Exit fullscreen mode

At the beginning I thought that it was my fault because I recreated the App Registration from scratch before the deployment.
After an hard googling session, I found an issue on GitHub on the ASP.NET Core repository: https://github.com/dotnet/aspnetcore/issues/33312

Solution

  • Edit the Client project file (double click on the project from Visual Studio 2022) and add the following lines:
    <ItemGroup>
        <TrimmerRootAssembly Include="Microsoft.Authentication.WebAssembly.Msal" />
    </ItemGroup>
Enter fullscreen mode Exit fullscreen mode
  • Delete all the "bin" and "obj" folders from the Server and App projects (manually)

  • Deploy the solution again and check the flag "Remove additional files at destination"

Image description

Enjoy your app with the Azure authentication :)

Top comments (0)