I am comfortable securing a blazor server and a blazor wasm (and api) app using Auth0, thanks to @andrea.chiarelli’s excellent documentation. It seems, however, that the new blazor “united” (Blazor Web App in Visual Studio) project type in .Net 8.0 allows for individual pages or components in a project to be wasm, server, static or server rendered. This is an attempt to side-step the limitations of wasm and server. If I decided to adopt this and have components with different rendering models its not clear to me how the Auth would work with Auth0. Just wondering whether @andrea.chiarelli has any plans to document how this might work? Thank you.
Hey @Ditchford, thank you again for appreciating my content on Blazor
Regarding support for the new Blazor model, I’m at the beginning of my exploration of OIDC integration, and I’ve found that there is no clear guidance on the Microsoft’s side so far.
Here are a couple of threads on the same request as yours:
- Authentication and Authorization in Blazor Web App for .net 8 · Issue #49870 · dotnet/aspnetcore · GitHub
- ASP.NET Core Blazor authentication and authorization | Microsoft Learn
Also, the current .NET 8 Blazor documentation still refers to server and client hosting without providing guidance for the mixed model.
I’d like to do some testing in the near future to add Blazor WebApp support to the Auth0 Templates for .NET as well, but I’d like to rely on official guidelines. Stay tuned.
In the meantime, any suggestions and references are welcome
Hey @andrea.chiarelli. Thanks for the info. I get the feeling Microsoft were rushed trying to get the mixed mode across the line for .Net 8.0. I think I’ll stick with .Net 7.0 for a while. If I do come across any information, I will let you know.
Re; “any suggestions/references” above:
I found this while looking at issue 49870 referenced above:
There is an unofficial example linked 3 weeks ago that may be relevant:
Hopefully helpful. I’m not planning on any WASM in my app re-write so I’m waiting on the latest .net8 server-only version of the above.
Thank you for sharing, @zgrose! I’ll take a look at it
Any additional updates on Auth0 for .NET 8 Blazor?
Hey @ammonmanning,
Thank you for joining the Auth0 Community and welcome!
Unfortunately, there are no updates currently. I’ll post here when I have updates.
Thanks for your interest.
Hey @andrea.chiarelli , I have spent some time with Blazor Web Apps and it appears to me that there a few issues presented by the new mixed rendering model. Examples being auth with third parties (as discussed) and state persistence for a user when switching between Wasm and Server interaction. My plan is to stick with globally defined Server or gloablly defined Wasm until these kinks have been ironed out, but it would be nice to get moved to .Net 8.0. So, my question is do you have any plans to update your existing documentation for Blazor Server and Blazor Wasm to .Net 8.0 - ignoring the existence of mixed mode for now. An example of what needs to be addressed is when you create a new .Net 8.0 Blazor Server project (for example) then there is no longer any reliance on .cshtml files (everything is first class razor components). Your documentation assumes the presence of login.cshtml and logout.cshtml. Thank you.
Hey @Ditchford,
Unfortunately I haven’t had the opportunity to deep dive into Blazor 8.0 yet, and I’m afraid I will not able to until next year due to other commitments.
My current article about Blazor stick with .NET 7.0 and honestly I’m not sure if it makes sense to update them to 8.0 right now since many devs are still using that version of .NET.
My plan is to experiment with Blazor 8.0 and come out with a possible solution for integrating Auth0. This will not be an “official” solution, of course, but just the results of my experiments shared with you all. However, it will happen with the new year, as soon as I can work on it.
Thank you for your patience
Firstly, thanks for the really useful content you provide.
When you are planning on deep diving into Auth0 for Blazor 8.0? How long are we looking at?
Hey @grantcolley,
Welcome to the Auth0 Community and thanks for your interest in the Auth0 + Blazor integration. I plan to work on it this month so I expect to publish an article by the end of January.
Thank you for looking into this. With the ‘End Of Support’ of .NET 7.0 just 4 months away, using .NET 8.0 for new our Blazor Server apps is crucial.
Hey folks, finally I did it. Here is my article about adding Auth0 authentication to Blazor Web apps based on .NET 8.
cc: @Ditchford, @zgrose, @ammonmanning, @grantcolley
Much appreciated!
Thank you.
Thanks for the update!!
Great post btw.
Very good one. Thanks!
Could you also touch on how to make use of Auth0 with Microsoft.AspNetCore.SignalR.Hub
classes? Things are a bit different in there in terms of using WebSockets and Auth0 together.
Hey @ozdmro,
I’m not familiar with SignalR Hub, but I think this could be an interesting area to explore.
Thanks for your suggestion
@ozdmro and @andrea.chiarelli we use SignalR/SignalRHubs and Auth0 together extensively. It’s a pretty easy integration with Blazor WASM;
From a razor component or injected service, you would write something like;
readonly IAccessTokenProvider _accessTokenProvider;
var hubConnection = new HubConnectionBuilder()
.WithUrl(BuildUrl(hubType, caseRecordId), options =>
{
options.AccessTokenProvider = async () =>
{
var accessTokenResult = await _accessTokenProvider.RequestAccessToken();
_ = accessTokenResult.TryGetToken(out var accessToken);
return accessToken?.Value;
};
})
.WithAutomaticReconnect()
.Build();
Good to know. Thanks!
Hey Andrea,
I followed the tutorial but i have an issue on the client side with blazor:
It looks like it has something to do with prerendering i guess.
thanks in advance,