configure-auth

Configure authentication and authorization in Blazor Web Apps across render modes.

Updated Jul 2, 2026
One-click install
npx skills add https://github.com/ecoDriverltd/FoundryAgentsExperiment --skill configure-auth-ecodriverltd
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: configure-auth
Source: https://github.com/ecoDriverltd/FoundryAgentsExperiment/tree/main/.agents/skills/configure-auth
Command: npx skills add https://github.com/ecoDriverltd/FoundryAgentsExperiment --skill configure-auth-ecodriverltd

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Adding authentication to a Blazor Web App is error-prone because behavior differs drastically between static SSR, interactive Server, and WebAssembly render modes. This Skill guides you through correctly wiring Identity, authorization, and auth state so you avoid common failures like null HttpContext, SignInManager exceptions, and lost auth state after WebAssembly loads. ## Core Features & Use Cases - Render-mode-aware setup: Register auth services, wire App.razor with AuthorizeRouteView, and conditionally apply render modes using AcceptsInteractiveRouting. - Page and component protection: Apply [Authorize] attributes, role and policy-based access, AuthorizeView conditional UI, and cascading AuthenticationState. - Identity page handling: Keep login and register pages as static SSR with [ExcludeFromInteractiveRouting] so SignInManager works correctly. - WebAssembly auth state: Serialize and deserialize AuthenticationState so users stay authenticated after WASM takes over from prerendering. - Use Case: You add [Authorize] to an admin page in a globally interactive Blazor app, but the Identity login page crashes. This Skill walks you through marking it with [ExcludeFromInteractiveRouting] and fixing App.razor. ## Quick Start Add authentication with role-based authorization to my interactive Blazor Web App and make sure the Identity login pages still work.

Frequently Asked Questions about configure-auth

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add authentication to a Blazor Web App?▼

Register AddCascadingAuthenticationState and AddAuthorization in Program.cs, then use AuthorizeRouteView in your router. For ASP.NET Core Identity, also configure AddAuthentication with Identity cookies and AddIdentityCore with roles and EF Core stores.

How to use [Authorize] and AuthorizeView in Blazor pages?▼

Add @attribute [Authorize] to a page to restrict access, optionally with Roles or Policy parameters. Use AuthorizeView with Authorized and NotAuthorized child content to conditionally render UI based on the user's authentication state.

Why does SignInManager throw an exception in interactive Blazor components?▼

SignInManager and UserManager depend on HttpContext, which does not exist in interactive Server or WebAssembly components. Move login logic to static SSR pages marked with [ExcludeFromInteractiveRouting] so they render through the server pipeline.

Why is the user anonymous after Blazor WebAssembly loads?▼

WebAssembly components cannot access server HttpContext, so auth state must be serialized during prerendering. Add AddAuthenticationStateSerialization on the server and AddAuthenticationStateDeserialization in the client Program.cs.

Why does NotAuthorized content never render in static SSR?▼

Static SSR pages render through the middleware pipeline, not the interactive router, so NotAuthorized content in AuthorizeRouteView is never shown. Handle redirects via middleware LoginPath configuration or a RedirectToLogin component instead.

When should I not use this Blazor auth configuration approach?▼

This guidance is specific to auth concerns and render modes. It does not cover general component authoring, non-auth prerendering issues, or managing non-auth cascading state, which require separate handling.