Issue: Authenticate state does not update after login when in main layout page, therefore IsInRole function does not work. Workaround: Force the browser to refresh.
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
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.
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
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 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
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
When we create a Blazor WebAssembly project with Default Authentication, it is configured with IdentityServer4 (IS4). If we upload our newly created project to production (Azure App Service, in my case), we will encounter the error: HTTP ERROR 500.30 – ANCM IN-PROCESS START FAILURE Which doesn’t tell us much. We can see the detail of... » read more
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