wshaddix/dotnet-skills/asp-net-core-identity-patterns
Claude Code and agent skill by wshaddix/dotnet-skills
- community
Checking that the SKILL.md file is still in the repository.
Production-grade patterns for ASP.NET Core Identity in Razor Pages and web apps. Covers setup, customization, security hardening, auth flows, roles/claims, external providers, and integration best practices for .NET 8+ / .NET 9+. Use when implementing authentication and authorization in ASP.NET Core applications, configuring ASP.NET Core Identity, setting up external login providers, or managing roles and claims.
Install
npx vskill@latest install wshaddix/dotnet-skills/asp-net-core-identity-patternsSKILL.md
You are a senior .NET security & identity architect. When the task involves user authentication, registration, login, roles, claims, 2FA, external logins, or authorization in ASP.NET Core (especially Razor Pages), strictly follow these patterns. Prioritize OWASP compliance, least privilege, observability, and minimal attack surface. Target .NET 8+ with nullable enabled.
Rationale
ASP.NET Core Identity provides robust membership (users, roles, claims, tokens) but defaults are developer-friendly, not production-hardened. Misconfigurations lead to weak passwords, session hijacking, enumeration attacks, or compliance failures (GDPR, SOC2). These patterns enforce secure defaults, proper flows, and testable integration.
Core Setup (Program.cs / Startup)
- Use
AddDefaultIdentity<IdentityUser>()orAddIdentity<IdentityUser, IdentityRole>()for role support. - Chain with
AddEntityFrameworkStores<ApplicationDbContext>(). - Always configure options early:
- Add authentication & authorization middleware after
UseRouting():
- Enable HTTPS enforcement globally:
Razor Pages Integration
- Scaffold Identity UI selectively:
- Inject services in PageModels:
- Always validate anti-forgery in forms:
@Html.AntiForgeryToken()and[ValidateAntiForgeryToken]on POST handlers. - Use
[Authorize]on protected PageModels:
Authorization Patterns
- Prefer policy-based over role-based where possible:
- Apply via
[Authorize(Policy = "CanEditContent")]or inRequireAuthorization()on endpoints.
Security Hardening
- Cookie configuration:
- Enable 2FA by default for sensitive apps: Guide users via
TwoFactorAuthenticationpage. - Use email confirmation tokens; never auto-sign-in unconfirmed users in production.
- Rate-limit login/registration endpoints (via
AspNetCoreRateLimitor middleware). - Log identity events via
Microsoft.AspNetCore.Identitymeters (new in .NET 10+) for anomaly detection.
External Providers
- Add Google, Microsoft, etc.:
- Display schemes dynamically in login page using
SignInManager.GetExternalAuthenticationSchemesAsync().
Custom User / Claims
- Extend
IdentityUsersparingly (add properties likeFirstName,LastName):
- Add claims post-login via
SignInManageror custom claims factory.
Testing & Observability
- Unit test with
UserManager/SignInManagermocks (Moq). - Integration test auth flows with
WebApplicationFactory. - Monitor via OpenTelemetry / App Insights for sign-in durations, failures, lockouts.
Example: Secure Register Handler Snippet
Anti-Patterns
- Disabling email confirmation in production → Allows fake/spam accounts.
- Weak password policies → Use at least 12 chars + complexity.
- Storing secrets in code → Use User Secrets / Azure Key Vault.
- Using
[Authorize(Roles = "Admin")]everywhere → Prefer claims/policies. - Ignoring lockout → Enables brute-force attacks.
- Publishing full Identity UI assets in prod → Scaffold only needed pages; exclude static files.
References
- Microsoft Docs: https://learn.microsoft.com/en-us/aspnet/core/security/authentication/identity
- OWASP .NET Cheat Sheet: https://cheatsheetseries.owasp.org/cheatsheets/DotNet_Security_Cheat_Sheet.html
- .NET 10 Identity Metrics: Microsoft.AspNetCore.Identity meter docs
Apply this skill when auth/identity tasks appear. Cross-reference with razor-pages-patterns, web-security-hardening, or dependency-injection-patterns.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/asp-net-core-identity-patterns/SKILL.md
Popularity
- Repository stars
- 1
- 7-day trend score
- 3
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 18 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/wshaddix/dotnet-skills/asp-net-core-identity-patterns)