With Blazor Web Assembly officially released I decided to take one of my side projects and write the front end in Blazor.
I was able to wire up Azure AD B2C for authentication.
What I wanted to do next was to take a look at the Claims that were available, I knew how to do this in ASP.NET MVC, but struggled with how to accomplish this with Blazor Web Assembly.
Finally stumbled across this article, ASP.NET Core Blazor authentication and authorization.
There are three ways to do it.
- AuthenticationStateProvider service
- Expose the authentication state as a cascading parameter
- AuthorizeView component
I created a Profile.razor
page that demonstrates the three was to achieve this, the code should be below.
I am sure there are other ways, and maybe better ways, so would appreciated any feedback!
Thanks!
Discover more from Matt Ruma
Subscribe to get the latest posts sent to your email.
Thanks — this was really helpful! I have been really struggling with my Blazor WASM on Azure Static Web App trying to figure out why my “client principal” is always null even if I’m logged in — and therefore I’m unable to use the “authenticated” role for controlling access to my Functions call. I still don’t know why it’s null, but at least now I can easily see what I do have — so maybe this will help me figure out an alternative way to control access.