Reputation: 1285
Does anyone know of a template or tutorial that uses blazor web assembly with azure ad auth?
Extra points if it uses c# web api as its server.
Upvotes: 2
Views: 1527
Reputation: 3075
Yes Secure an ASP.NET Core Blazor WebAssembly hosted app with Azure Active Directory
Upvotes: 3
Reputation: 914
The following is a recent addition to Microsoft's docs (May 2020). I'm giving it a go right now.
Secure an ASP.NET Core Blazor WebAssembly hosted app with Azure Active Directory
It uses Blazor WebAssembly for the frontend and an ASP.NET core backend.
One part it fails to mention clearly is the need for Microsoft.Extensions.Http
in the client app. Available in NuGet.
Edit: Sorry for the excitement => sharing this without testing. I just completed the steps and I confirm that it works!
Upvotes: 0
Reputation: 3702
In Blazor WebAssembly apps, user authentication and authorization must be handled by the back end web Api, because all client-side code can be modified by users.
In Blazor WebAssembly you can implement an AuthenticationStateProvider
which calls your web Api to get details about the authorization state of the user.
Then you can use the AuthorizeView
component to show or hide content depending on the users roles etc.
Interestingly, it does not matter for your Blazor App whether you use Azure AD, Azure AD B2C or any other authentication provider, because the authentication is handled by the Api. Only the Sign In and Sign Out url’s will depend on your authentication provider.
A clear description you can find in Blazor Prepare for Authorization
Source code example in https://github.com/Forestbrook/BlazorAuthorizationExample.
Upvotes: 1
Reputation: 7720
From what I understand this is not yet a directly supported scenario. There is a deployment guide here but it doesn't provide guidance for the authentication aspect of this.
I would suggest requesting this in User Voice so that the product team can prioritize this. I have seen a lot of people request this.
Upvotes: 1