-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Azure AD Authentication Error with Blazor wasm #38082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Just encountered this exact same issue, using .NET 6 final. Thanks for writing this up! Going to have to put a stop to our .NET 6 migration until this is resolved. We're using Azure AD for authentication. |
Did a little digging into the issue. The error comes from this line, due to loginMode being null: https://github.com/dotnet/aspnetcore/blob/v6.0.0/src/Components/WebAssembly/Authentication.Msal/src/Interop/AuthenticationService.ts#L197 We're setting loginMode so it shouldn't be null. Problem is due to the entire _settings object (AuthorizeServiceConfiguration) missing a lot of properties. The cause of that appears to be something in the trimming logic in .NET 6 that's dropping those properties -- if I set |
In an effort to keep publish trimming enabled - I got around the immediate "Cannot read properties of undefined (reading 'toLowerCase')" error by running something similar to the snippet below after running dotnet publish: $jsPath = "$(Build.ArtifactStagingDirectory)/client/wwwroot/_content/Microsoft.Authentication.WebAssembly.Msal/AuthenticationService.js"
$jsContent = Get-Content $jsPath -Raw
Set-Content $jsPath -Force -Value $jsContent.Replace(".loginMode.toLowerCase", "?.loginMode?.toLowerCase") But like @IGx89 said, that error was a sign of a larger problem so I would not recommend pursuing this workaround. The next error seems to be a missing client ID in the redirect URL:
Really hoping this gets resolved before .NET 7! 🙏 |
Same for me using .NET 6 (GA), setting |
@albx @IGx89 Another workaround so you don't have to trim the whole publish (works for wasm and hosted wasm) Under program.cs in client project set the login mode under msal authentication Then in the csproj file for the client project below the ItemGroup with all your packagereferences add this itemgroup
Delete your client project folders bin and obj, clean the solution, close and open VS and then rebuild and publish. |
I have the same issue in a hosted Blazor app which uses AD B2C. Using
works but what proposed by @ddfxraven does not in my app and an exception is thrown in the console saying that loading MSAL was blocked. |
Facing the same issue with Blazor Webassembly .NET6 deployed on Linux via GitHub pages.
|
Could you please me be more specific to the solution you found? Having the same issues as everyone above. |
@limitx3m GitHub Pages is Linux hosted so for SPA and Azure AD to work correctly I had to make changes at multiple places,
With this we have deployed multiple Blazor WebAssembly SPA to GitHub pages, including Progressive Apps |
This workaround worked for me |
We believe this was addressed recently as part of #43954. A fix will be available in 7.0-rc2. If you still run into this issue after updating, please let us know and we'll reopen the issue. |
Hi, I am having this exact same issue and tried everything mentioned here. I created a new Blazor Webassembly project as a poc with Identity scaffolded. However, when I publish to Azure blob storage with static web app activated this error appears. |
@abonniko can you try with the latest 7.0 RC2 release? |
Hi @javiercn, yes it works when I target net7.0, thank you. |
Describe the bug
Fails when trying to log in to a Microsoft account with a published blazor wasm application using DotNet 6.
The error states as follows :
"There was an error trying to log you in.
Error: Cannot read properties of undefined (reading 'toLowerCase')"
When trying to to log in while in debug mode, it works fine.
The DotNet 5 application logs in the user successfully in both debug mode and with the published application.
To Reproduce
Create a blazor wasm application with DotNet 6 that uses Microsoft Graph authentication. Publish the application, then try signing in from the hosted application.
The public repository:
https://github.com/Ryu-Sch/GraphLogin
Further technical details
dotnet --info Output
The text was updated successfully, but these errors were encountered: