agentleFS
zdanovichnickzdanovichnick/dotnet-pilot/skills/authentication/SKILL.md

authentication

Skill5 starsChanged 6 days agoMITView on GitHub

JWT bearer auth, ASP.NET Identity, OIDC, and policy-based authorization patterns for ASP.NET Core APIs.

20 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use monitoring, openapi and 2 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • rogue-dev-studioSkill

    monitoring

    Claude monitoring and usage tracking tools (UV, claude-monitor, claude-usage-cli). Use when the project needs this capability or the user / team manifest asks for it. Use for specialized `monitoring` work when listed in TEAM.yaml or explicitly requested.

    Also in 3 projects that use this

  • ffsshhttiikkSkill

    openapi

    OpenAPI/Swagger specification and documentation

    Also in 3 projects that use this

  • VercelSkill

    messaging

    Use when turning settled positioning into the lines other people will reuse: the message hierarchy, value propositions per audience, objection handling, and the proof behind each claim.

    Also in 3 projects that use this

  • JohnJBorenSkill

    ci-cd

    CI/CD pipeline design, GitHub Actions, testing automation, and deployment strategies

    Also in 4 projects that use this

The file

Files
SKILL.md

Authentication & Authorization Patterns

Reference for securing ASP.NET Core APIs. Covers JWT bearer, ASP.NET Identity, OIDC, policy-based authorization, and resource-based authorization.

Quick Decision Guide

ScenarioApproach
API consumed by SPAs or mobile apps with an external IdPJWT Bearer
Server-rendered app with local user accounts + rolesASP.NET Identity
Federated login (Google, Entra ID, Keycloak)OIDC + AddOpenIdConnect
Fine-grained permissions beyond rolesPolicy-based + IAuthorizationHandler
Resource ownership check (user can only edit their own order)Resource-based authorization

Required Pipeline Order

// Order matters — authentication must run before authorization
app.UseAuthentication();  // sets HttpContext.User
app.UseAuthorization();   // evaluates policies

References

Load only the file the task needs:

FileCovers
references/jwt-bearer.mdAddJwtBearer against an IdP; symmetric-key validation for internal services without one
references/aspnet-identity.mdDatabase-backed users and roles with ASP.NET Identity
references/oidc.mdAddOpenIdConnect with an external provider
references/authorization.mdRegistering and applying policies; resource-based IAuthorizationHandler (requirement, handler, endpoint usage)
references/claims-and-schemes.mdReading claims from HttpContext.User; multi-scheme authentication

Do / Don't

DoDon't
Set ClockSkew = TimeSpan.ZeroAllow the default 5-minute token expiry grace period in production
Validate both iss and audDisable issuer or audience validation for convenience
Use FallbackPolicy to require auth by defaultRely on [Authorize] placement — it's easy to forget
Use policy-based authorization for permissionsHard-code role strings in [Authorize(Roles = "...")] throughout controllers
Use resource-based authorization for ownership checksPut ownership logic inside domain services
Pick one claim-name scheme: raw names (MapInboundClaims = false + NameClaimType/RoleClaimType) or ClaimTypes.*Mix "sub" lookups with ClaimTypes.NameIdentifier lookups — one of them returns null
Store permissions as claims in the tokenRe-query the DB for permissions on every request
Use RequireAuthenticatedUser() as fallback policyOpen all endpoints and add [Authorize] selectively
AllowAnonymous() on health check / public endpointsForget to exempt health endpoints from the fallback policy

See Also

  • skills/error-handling/SKILL.md — TypedResults.Forbid() and mapping auth failures to ProblemDetails
  • skills/aspnet-api-patterns/SKILL.md — endpoint conventions for protected routes

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.