Skip to content
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

Blazor - Wasm pre-rendering (without server interactivity) - MSAL Auth on client side only not working #58833

Closed
1 task done
michelkommers opened this issue Nov 7, 2024 · 9 comments
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-msal This issue is related to MSAL usage in Blazor ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Status: Resolved

Comments

@michelkommers
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I am struggling with setting up a Wasm + SSR (ExcludeFromInteractiveRouting) + prerender + Client Side MSAL Auth with AD B2C ( without Blazor server interactivity).

In other words, a setup that runs on wasm only and is pre-rendered in SSR without auth working, but the auth must work on the client side only, so we can refresh tokens and etc etc without depending on the server side.

Right now, the issue seems that it never uses msal and tries to use the server side or gives error while attempting to convert one auth provider to other etc... this worked back in .net 5 with a super odd setup that i tried to put in .net 8 but doesn't work, tested with .net 9 RC 2 and same thing.

Can you provide a guide for this setup using .net 9?

Putting @guardrex because I didn't find that setup in any docs (and it was previously supported in .net 5 I think, and it seems that the docs that covered that were removed)

Expected Behavior

A setup to make wasm pre-rendering work without auth on the server (SSR) but working on the client with MSAL, without using server interactivity.

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

No response

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Nov 7, 2024
@guardrex
Copy link
Contributor

guardrex commented Nov 7, 2024

Yes! if you're referring to a hosted WASM scenario. The idea was that devs would start building Blazor Web Apps and eventually move hosted WASM apps to BWAs.

Based on how your discussion goes here, I'll open an docs issue if we need to provide additional coverage. I won't be surprised if they say that that's an unsupported scenario at this time.

@michelkommers
Copy link
Author

That would be a 'super' regression. I mean, this worked back in .net 5 ( I had it working in previous projects), and the issues seems to be only in the Auth. the rest seems to work fine.

@michelkommers
Copy link
Author

For more context, this is how it worked previously:
#15253 (comment)

@mkArtakMSFT mkArtakMSFT added the feature-blazor-msal This issue is related to MSAL usage in Blazor label Nov 7, 2024
@mkArtakMSFT
Copy link
Member

Thanks for contacting us.

First and foremost, if you want to have prerendering support, that means you also have to think about supporting authentication on the server, as prerendering happens on the server.
Our recommended setup for how to do this is here: https://learn.microsoft.com/aspnet/core/blazor/security/blazor-web-app-with-entra?view=aspnetcore-9.0

If you'd like to support auth only on the client, you will have to disable prerendering.

@mkArtakMSFT mkArtakMSFT added the ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. label Nov 7, 2024
@guardrex
Copy link
Contributor

guardrex commented Nov 7, 2024

@michelkommers ... I'm going to make a tracking item entry to look at this for coverage at a strategic spot in the Security and Identity overview article, and it will at least be cross-linked from the Prerendering article.

@guardrex
Copy link
Contributor

guardrex commented Nov 7, 2024

BTW ... I noticed that I did version-out the coverage at ...

https://learn.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/additional-scenarios?view=aspnetcore-7.0#prerendering-with-authentication

... when BWA/8.0 arrived. I'll work a section back into the docs on this subject per my tracking item. I might reach that soon, but things are a bit crazy at the moment with 9.0 coming out. I'll get to it ASAP 🏃‍♂🏃‍♂🏃‍♂🏃‍♂.

@michelkommers
Copy link
Author

@guardrex and @mkArtakMSFT I actually got it working after spending a few hours dealing with 'bug after bug'.

The main thing is.... I had to make 'fake' services in the server program.cs, after that I excluded the page 'authentication/xxx' from being pre-rendered due to the 'RemoteAuthenticatorView'.

I will do further tests tomorrow to make sure everything is working nicely, but let me know if a sample would help the docs etc.

@guardrex
Copy link
Contributor

guardrex commented Nov 8, 2024

I don't think that they'll want to cover a workaround approach, but I'm 👂 if they do.

Copy link
Contributor

This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.

See our Issue Management Policies for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-msal This issue is related to MSAL usage in Blazor ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Status: Resolved
Projects
None yet
Development

No branches or pull requests

3 participants