Blazor Server Custom Authentication [Blazor Tutorial C# - Part 11]

preview_player
Показать описание
Blazor Tutorial C# - Part 11 is a tutorial video which explains everything about Blazor Authentication and Authorization [Blazor Auth]. In this video, we create a custom blazor server authentication state provider for implementing Blazor Server Custom Authentication. The blazor server custom authentication state provider will be inherited from Blazor's Authentication State Provider.

.Net Blazor Tutorial Playlist link:

Blazor Server apps operate over a real-time connection that's created using SignalR. Authentication in SignalR-based apps is handled when the connection is established. Authentication can be based on a cookie or some other bearer token. Blazor Server apps are configured for security in the same manner as ASP.NET Core apps.

The built-in AuthenticationStateProvider service for Blazor Server apps obtains authentication state data from ASP.NET Core's HttpContext.User. This is how authentication state integrates with existing ASP.NET Core authentication mechanisms.

AuthenticationStateProvider is the underlying service used by the Blazor AuthorizeView component and CascadingAuthenticationState component to get the authentication state.

You don't typically use AuthenticationStateProvider directly. The main drawback to using AuthenticationStateProvider directly is that the component isn't notified automatically if the underlying authentication state data changes.

The AuthenticationStateProvider service can provide the current user's ClaimsPrincipal data

If authentication state data is required for procedural logic, such as when performing an action triggered by the user, obtain the authentication state data by defining a cascading parameter of type Task of AuthenticationState.

If user.Identity.IsAuthenticated is true, claims can be enumerated and membership in roles evaluated.

AuthorizeRouteView Class combines the behaviors of Blazor AuthorizeView and Blazor RouteView, so that it displays the page matching the specified route but only if the user is authorized to see it.

The AuthorizeView component selectively displays UI content depending on whether the user is authorized. This approach is useful when you only need to display data for the user and don't need to use the user's identity in procedural logic.

The content of Authorized and NotAuthorized tags can include arbitrary items, such as other interactive components. A default event handler for an authorized element, such as the SecureMethod method for the button (Display Greeting Button) element in the video example, can only be invoked by an authorized user.

The AuthorizeView component supports role-based or policy-based (blazor authorization policy). For role-based authorization [blazor authorization], use the Roles parameter authorization and for policy-based authorization, use the Policy parameter.

The [Authorize] attribute (Blazor Authorize Attribute) also supports role-based or policy-based authorization. If neither Roles nor Policy is specified, [Authorize] uses the default policy.

The Router component, in conjunction with the AuthorizeRouteView component, allows the app to specify custom content by providing Authorized, NotAuthorized & Authorizing tags.

Video Chapters:
0:00 - Intro
0:33 - Final Output
3:37 - Configuring Authentication and Authorization
13:18 - Custom UI based on User Roles
20:26 - Running Application and more

#blazor #codingdroplets #blazorauth
Рекомендации по теме
Комментарии
Автор


🔗Blazor Tutorial Series Playlist link:

CodingDroplets
Автор

Absolutely the best i have seen on the web for a "how to develop a custom authentication for blazor server!". you covered all bases and that is simply awesome!

chrisglick
Автор

Excellent minimum Authentication Example. Straight to the topic and without any distraction.

ericngo
Автор

I've completed all the parts and have successfully implemented CRUD operations and authentication with a local database, using Entity Framework. I have significantly improved. Great tutorial, many thanks!

tomPearson
Автор

Very nice tutorial. You briefly showed the final product without forcing audience to wait to the end of the video. Also you did not dive into irrelevant database details, useless jokes etc. Clear and fluent narrative. Thanks!

manonthecorner
Автор

This is the best video on youtube for this topic. Explains everything from the vanilla project, and it is quick, comprehensive and to the point, and it works. On top of that, for me the explanation about server render mode in conjunction with ProtectedSessionStorage at 21:32 explained exactly the problem I'd had with other attempts to use ProtectedSessionStorage, probably from following blazor wasm tutorials, and now I know why that was. Thank you!

alan-
Автор

Absolutely outstanding! This is exactly what I have been looking for! You literally took me step by step through a perfectly rendered security implementation for my Blazer Server applications. Even your variable names and coding standards were exactly how I would have implemented them. Excellent video! Thank you so much!

TampaCEO
Автор

This is the first time I see a content creator answering comments and with a deep explanation indeed. Subscribed! Of course, the video is also superb, since there are very few videos in this topic. Blessings!

oddikaro
Автор

Por fin un tutorial simple conciso, directo al punto, muchisimas gracias por el video!!!

asanoguera
Автор

Thank you! One of the clearer step by step tutorials I've seen on a subject I have struggled with. This is the first time I've actually understood what is going on. Appreciate that you kept the design simple and basic with clear steps.

Going to follow it through using minimal API I've developed for our product, which has a JWT based auth endpoint.

nb. It would be nice if you included your github code links in the summary, though I found them easily enough from your channel About page.

blackpaw
Автор

El mejor de lo mejor de los tutoriales que he visto, y he buscado muchos por este tema. Gracias

JAVIERENRIQUEVILLALBAESPINOSA
Автор

Great video! I love this tutorial style, no waffle or over complication. Great work, thank you.

hello-matthew
Автор

🔗Blazor Tutorial Series Playlist link:

CodingDroplets
Автор

This video is amazingly concise and helpful. Thank you!!!

ivanshepelev
Автор

Great video, you helped me a lot.
For those who want to recreatte this:
Watch out VS sometimes suggests you code parts and the ifs are reversed e.g. instead of if(userSession != null) it suggests if(userSession == null), took me some time to realize that.

beneh.
Автор

THANK YOU SO MUCH sir! This is exactly what I searched for. I searched through StackOverflow and I didn’t found it. I searched in other places also. You are my hero!

torrvic
Автор

Really useful...have been looking for something like this for a while. Well explained and clearly coded. Thanks.

GerryNoble
Автор

Very good explanation. Thank you very much. I watched much login page on Blazor videos before this. But I found best answer at the end.

alikemalkulful
Автор

You're the GOAT.

Thank you so much, this is really underrated!

eduardrivas
Автор

I really appreciate your clear explanations and work pace. Your tutorial provides an excellent foundation that can be easily applied to own projects :)

HaiTzung