AuthenticationStateProvider vs AuthenticationState

AuthenticationStateProvider AuthenticationState AuthenticationStateProvider vs AuthenticationState Blazor has a built-in service called AuthenticationStateProvider service. This service obtains authentication state data from ASP.NET Core’s HttpContext.User. This is how authentication state integrates with existing ASP.NET Core authentication mechanisms. It is this service that is used by AuthorizeView component and CascadingAuthenticationState component to get the authentication state. Don’t use AuthenticationStateProvider directly. Use the AuthorizeView component. The main drawback to using AuthenticationStateProvider directly... » read more

Custom Identity Claim in Blazor

1. Create new field of string type in the AspNetUsers table of Identity database. 2. Add field to ApplicationUser class. (Server) 3. Create new class called CustomUserClaimsPrincipalFactory 4. Add to ConfigureServices in Startup.cs (Server) Note: As soon as the line .AddClaimsPrincipalFactory<CustomUserClaimsPrincipalFactory>(); is added, role does not work anymore.

Secure an ASP.NET Core Blazor WebAssembly hosted app with Identity Server

Note: Need to configure both .Client and .Server projects. .Client Create a new class called CustomUserFactory.cs Add to Main of Program.cs (Client) .Server Add to ConfigureServices of Startup.cs (Server) Result Index.razor (Client) OrgAdminOnly.razor (Client) Sources: https://docs.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/hosted-with-identity-server?view=aspnetcore-3.1&tabs=visual-studio

Store does not implement IUserRoleStore

When configuring Blazor Identity … Error: NotSupportedException: Store does not implement IUserRoleStore<TUser>. var roles = await _signInManager.UserManager.GetRolesAsync(user); Fix: Add .AddRoles<IdentityRole>() to Configuration of Startup.cs

ASP.NET Core Blazor authentication and authorization

ASP.NET Core supports the configuration and management of security in Blazor apps. Security scenarios differ between Blazor Server and Blazor WebAssembly apps. Because Blazor Server apps run on the server, authorization checks are able to determine: The UI options presented to a user (for example, which menu entries are available to a user). Access rules... » read more

Securing Blazor WebAssembly with Identity Server 4

The new Blazor WebAssembly 3.2.0 includes support to client side authentication, which makes relatively simple to implement OpenID Connect and OAuth2 in your single page application. In other words, it means that we can finally build applications with the most recent industry standards in terms of security, enabling complex authentication scenarios and integrating them with the most widely used identity providers out there. Speaking of identity providers,... » read more

Setting up Identity Roles

We need to add the role specific services to our application. To do this, we need to update the code in the ConfigureServices method of the Startup class. The IdentityRole type is the default role type provided by ASP.NET Core Identity. But you can provide a different type if it doesn’t fit your requirements. Next, we’re going to seed our database... » read more