Add Auth0 Authentication to Blazor Hybrid Apps in .NET MAUI

The code provided in this article is for .NET 8.0. It has not been tested with .NET 9.0

1 Like

Nevermind, I was missing AddCascadingAuthenticationState().

Cool! Thank you for sharing :slightly_smiling_face:
So this means it’s working in .NET 9 as well, right?

Yes it does as long as you don’t forget the cascading authentication state :slight_smile:

1 Like

Hello Andrea, thanks for the article.

I only have one question related to the Blazor Web project. My Maui solution has 3 projects, the mobile the shared project and the web project (Blazor WASM). Currently only the Mobile works, but when I run the web I am getting error:

rit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Could not load type of field ‘Auth0.OidcClient.WebAuthenticatorBrowser+d__0:<>u__1’ (3) due to: Could not load file or assembly ‘Microsoft.Maui.Essentials, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ or one of its dependencies.
System.TypeLoadException: Could not load type of field ‘Auth0.OidcClient.WebAuthenticatorBrowser+d__0:<>u__1’ (3) due to: Could not load file or assembly 'Microsoft.Maui.Essentials, Version=1.0.0.0

In order to make the authentication to work for the web project on Blazor WebAssembly should I do the implemention with the traditional approach for Blazor WASM ? or there is a way to use the same logic for all ?

Thanks

Hey @dsapo,
You can’t use the MAUI SDK in a Blazor WASM app.
A Blazor WASM app is still a web app, not a native app. You should use the approaches described here or here (it depends on the .NET version and/or the hosting model)

1 Like