aspnetcore: .NET 8 preview7 Blazor WASM AAD authentication ends with There was an error trying to log you in: '"undefined" is not valid JSON'
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
I am getting the same issue as described in #44981 again: after coming back from login at Azure AD the user sees ‘There was an error trying to log you in: ‘“undefined” is not valid JSON’’ at the ‘authentication/login-failed’ route.
However, after manually navigating around the token is available so it kind-of worked anyway.
Same as with the previous issue, adding the following solves the issue, so I suspect a similar cause:
<ItemGroup>
<TrimmerRootAssembly Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" />
</ItemGroup>
Also: error does not appear during development, only after publish also pointing to the linker
Expected Behavior
No error should be displayed after the redirect if the operation was successful.
Steps To Reproduce
Standard Blazor WASM application using Microsoft.Authentication.WebAssembly.Msal (8.0.0-preview.7.23375.9), set up to use ‘redirect’ and not the ‘pop up’ auth option.
Exceptions (if any)
No response
.NET Version
8.0.100-preview.7.23376.3
Anything else?
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 22
- Comments: 54 (7 by maintainers)
Commits related to this issue
- fix: logout bug in blazor see https://github.com/dotnet/aspnetcore/issues/49956#issuecomment-1992857288 — committed to Muddi-Markt/ShiftPlanner by maxreb 3 years ago
In the
8.0.0release:RemoteAuthenticatorView.LogInFailedcontext (notably, downgrading MSAL to7.0.13yields an error:"undefined" is not valid JSON).Microsoft.Authentication.WebAssembly.Msalwhen publishing the app resolves the issue immediately.I believe this should not be classified as “technical debt” for future “.NET 9 Planning”, but rather recognized as a regression that could potentially cause significant issues for users.
Thanks for contacting us.
We’re moving this issue to the
.NET 9 Planningmilestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it’s very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.Same issue on .NET 8 and I have tried adding both to the trimmer exception. Pushing this to .NET 9 is unacceptable. This has been going on long enough. It’s been years now.
For anyone following along, I had a similar issue here #54515 that I was hoping would be fixed with 8.0.4. I updated and that does not seem to be the case.
Can we stop closing tickets until something is confirmed as fixed AND released? I even asked in my other issue how I’d confirm that this works locally so I don’t have to do a full build and deploy, but no dice.
I did not try
<PublishTrimmed>false</PublishTrimmed>, but I did make sure this time to clean all relevant bin+obj folders - now deploying works for me with only one assembly “rooted”:Is this expected to be folded in to the 8.0.4 release?
Using Net8.0, TrimmerRootAssembly does not fix the issue. Please help.
I experienced the same issue when upgrading to .NET 8.0 with Azure B2C. I had to add the following to get it to work.
Specifying just Microsoft.Authentication.WebAssembly.Msal alone did not work for me.
Key functionality (authentication) of a framework (in this case Blazor) being shipped completely broken out of the box in an LTS release when you’ve known about it since preview builds is completely unacceptable, closing an issue when it is NOT fixed, and expecting users to jump through hoops to find a CLOSED GitHub issue with a workaround is even worse. Doing things like that, alongside other shortcomings of auth in Blazor (like using a deprecated version of oidc-client-js) basically ensures Blazor will never see serious adoption.
yes with
<PublishTrimmed>false</PublishTrimmed>the problem is gone. Even it was a hard way to test it. I had to clean all obj folders manually. Before that mono was out of sync and a cleanup did not work.so I tried
with trimming again and delete all obj folders. And it is working.
I can confirm. The issue is solved in our case by mentioning only one root assembly:
Thanks for contacting us.
We’re moving this issue to the
.NET 9 Planningmilestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it’s very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.why is this still an issue in .NET 8? yes there is this fix but come on
In .NET 8 and have the same issue. The TrimmerRootAssembly fix did not work for me. The problem occurs in both Chrome and Edge.
Worth noting though that it doesn’t happen locally, only in release mode in a deployed environment. And it happens on both log in and log out.
I also tried the workarounds from issue #43293, but no success with those either.
It looks like the fix might be included in the upcoming 8.0.5, which based on the release cadence so far, I’d guestimate that it’ll be out on May 7th
https://github.com/dotnet/aspnetcore/pull/54655
You’re right though, they really need to do something about the underlying oidc-client, there hasn’t been a release of it since 2021 and the repo was archived in March 2022, the replacement oidc-client-ts is actively maintained, regularly updated and well supported - they really do need to do something.
Something that caught me out was I also needed to clear cache after adding
Edit: This actually didn’t fix it.
@halter73 I forked your repo and set it up like my project, relevant changes:
options.ProviderOptions.DefaultAccessTokenScopes.Add("https://{TENANT}.onmicrosoft.com/{SERVER API APP CLIENT ID}/API.Access");I useoptions.ProviderOptions.DefaultAccessTokenScopes.Add("{SERVER API APP CLIENT ID}/.default");(I honestly can’t remember why any more)After these changes (+ entering my own tenant and client of course) and running
dotnet publish -c Release(afaik theReleasetag is now the default anyway, but I’m so used to writing it) I threw thewwwrootcontent on the server, tried the login, and:Don’t think my setup is totally unusal, but please tell me if I’m doing something I’m not supposed to do (the redirect is a requirement though, can’t change that). I hope that helps you to reproduce the issue!
The fix below does not help me, and I only experience the issue when deploying (Azure App Service). Had no issue with .NET 7.
Had the same issue. Going from .NET 7 -> .NET 8, I had to add the following in the Client csproj:
This resolved the issue.
Another thing I noticed was that it was only in Microsoft Edge the problem occured, in Google Chrome there was never an issue.
@czlatea Doesn’t work for me; tried both and just Authentication in both Client and Server projects using .net 8
pls fix
Hi @halter73. Many of us in this thread only experienced the issue when we deployed to Azure, localhost worked fine.
FWIW (to help reproduce) - I had this issue after following the steps here https://learn.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/standalone-with-microsoft-entra-id
Solution runs fine on my localhost but shows the JS error once deployed to Azure.
The same workaround works for me.
Thankful I found this thread. Experienced the issue upgrading our .NET 7.0 Blazor WASM PWA to .NET 8.0. Applied the suggested changes, which alongside removing the bin/obj folders and a full rebuild worked a treat.
<ItemGroup> <TrimmerRootAssembly Include="Microsoft.Authentication.WebAssembly.Msal" /> <TrimmerRootAssembly Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication"/> </ItemGroup>This doesn’t really apply in a CI/CD setup does it? I run
dotnet publishin my build, publish the artifacts from thepublishfolder, and then my release deploys those artifacts to the Azure AppService.Just setup a new project on the hosted wasm model and I had to put this in the client project for the authentication to work for azure AD. On the Microsoft Identity Platform it worked without this.
you have to put it in the wasm project and please don’t forget to delete the bin and obj folders for all projects before you deploy
You could attempt to turn off trimming by setting
<PublishTrimmed>false</PublishTrimmed>to verify if trimming is the root cause of the issue. If this resolves the problem, you can then proceed to “root” the assemblies one-by-one to identify which one is effective.To all who report that the trimming setting does not address their issue – it’s probable you’re encountering a different problem. A key symptom of this issue is: it only appears after publishing your project (which is when assembly trimming occurs). If you’re facing authentication problems in a development environment (like when running from Visual Studio), you’re dealing with a separate issue, and the
TrimmerRootAssemblysetting will not assist you.@kyleherzog Sorry for the confusion. Actually I do have both the MSAL and WebAssembly.Authentication rooted and it is probably the
Microsoft.AspNetCore.Components.WebAssembly.Authenticationwhich is the important one for this symptom.