ASP.NET Core
supports configuration and security management in Blazor
applications
Security scenarios are different for Blazor Server
and Blazor WebAssembly
projects
In Blazor Server
projects, authorization checks are able to determine:
- The user interface options presented to the user
- Access rules for application areas and components
In Blazor WebAssembly
projects authorization is used only to determine which user interface options will be presented
A WebAssembly
application cannot enforce authorization access rules
Blazor
uses existing ASP.NET Core
authentication mechanisms to establish the user's identity
Blazor Server
applications operate over a real-time connection that is created using SignalR
The Blazor Server App
template allows you to configure the authentication mechanism
Authentication uses cookies or another process to determine the user's identity and uses the same mechanism as ASP.NET Core
applications
The project can track the identity of the logged in user and apply authorization rules
In Blazor WebAssembly
projects authentication checks can be ignored because all client-side code can be modified by the user
We can implement a custom AuthenticationStateProvider
service for Blazor WebAssembly
applications
AuthenticationStateProvider
is an internal service that obtains authentication status data from HttpContext.User
from ASP.NET Core
It is used by the AuthorizeView
and CascadingAuthenticationState
components to obtain the authentication state
- In the Client project, import the
Microsoft.AspNetCore.Components.Authorization
package - Include in the
_imports.razor
file of theClient
project the reference to the@using Microsoft.AspNetCore.Components.Authorization
namespace - Include in the
Startup
class of the Client project, in the ConfigureServices method, the authorization service services.AddAuthorizationCore()