What is the purpose of the AuthenticationStateProvider, and how do you customize it to handle JWT-based auth in a WASM app?

Last updated 5 July 2026

  • AuthenticationStateProvider supplies the current user's ClaimsPrincipal to AuthorizeView and [Authorize] via GetAuthenticationStateAsync().

  • For JWT, subclass it to read the token from storage and build a ClaimsIdentity with an auth type (so IsAuthenticated is true) and correct role claims.

  • Call NotifyAuthenticationStateChanged on login/logout, register it in DI, and attach the token as a Bearer header (e.g. via a DelegatingHandler).

  • https://learn.microsoft.com/en-us/aspnet/core/blazor/security/authentication-state?view=aspnetcore-10.0
  • https://www.youtube.com/watch?v=iq2btD9WufI
  • https://medium.com/@shahriyarali08/authentication-and-role-based-authorization-in-blazor-wasm-using-jwt-and-7bcc12317ea
  • https://code-maze.com/authenticationstateprovider-blazor-webassembly/
  • https://code-maze.com/blazor-webassembly-authentication-aspnetcore-identity/
All Blazor interview questions