auth-patterns

Enforces authentication and authorization rules for BFF cookies, JWT validation, and claims extraction.

7|3|Updated Sep 23, 2025
One-click install
npx skills add https://github.com/islamu-ngo/Event --skill auth-patterns-islamu-ngo
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: auth-patterns
Source: https://github.com/islamu-ngo/Event/tree/main/.agents/skills/auth-patterns
Command: npx skills add https://github.com/islamu-ngo/Event --skill auth-patterns-islamu-ngo

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? It prevents inconsistent authentication and authorization implementations in a .NET BFF architecture, such as tokens leaking to the browser, divergent user ID extraction helpers, and UI gating that drifts from the server authorization contract. ## Core Features & Use Cases - BFF Token Handling Rules: Keeps tokens in HttpOnly cookies and forwards Bearer tokens to the API so the browser never sees them. - Canonical Identity Extraction: Pins a single claim chain (sub, nameidentifier, sid, internal_user_id) via GetPlatformUserId, with mediator-based resolution for ATProto DIDs and Google subjects. - Authorization Pipeline Guidance: Documents JWT aud/azp validation, AuthorizationBehavior routing to Cerbos or FallbackAuthorizationService, and HATEOAS _links as the only client-side gating source. - Use Case: When fixing a 401/403 bug or adding an authorized endpoint, load this Skill to apply the correct claim extraction, endpoint protection defaults, and verification test commands. ## Quick Start Ask the AI to review your new authorized endpoint or authentication change against the auth-patterns rules before committing.

Frequently Asked Questions about auth-patterns

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

FAQPage Schema
How do I extract the user ID from a ClaimsPrincipal in ASP.NET Core?▼

Call the existing GetPlatformUserId extension, which tries sub, then nameidentifier, then sid, then internal_user_id, accepting only GUID-parseable values. Use GetRequiredPlatformUserId when a missing identifier should throw UnauthorizedAccessException instead of returning null.

How should JWT validation handle Keycloak multi-client tokens?▼

Validate issuer, audience, and lifetime with a five-minute clock skew, and accept the token when either aud or azp matches an allowed client such as islamu-event-api or islamu-event-blazor. Validating only aud or only azp lets unauthorized clients present otherwise valid tokens.

Why should tokens not be stored in localStorage with a BFF pattern?▼

Storing tokens in localStorage or sessionStorage bypasses the BFF boundary and exposes them to browser-side attacks. The BFF keeps tokens in HttpOnly cookies and forwards a Bearer token to the API, so the browser never sees them.

Can I gate UI actions by checking user roles or claims directly?▼

No, UI action gating must use the HAL _links returned by the server, which are produced by the Candidate, Normalize, Batch, and Materialize pipeline and fail closed. Role or claim inspection on the client drifts from the server authorization contract.

What happens when the identity provider subject is not a platform user ID?▼

ATProto DIDs and Google subjects are not GUIDs, so the claim chain returns null unless internal_user_id is present. Resolve the linked local account with mediator.ResolveCurrentUserIdAsync instead of writing a fallback extraction helper.