cratis/ai.distribution/auth-and-identity
Claude Code and agent skill by cratis/ai.distribution
- community
Checking that the SKILL.md file is still in the repository.
Use this skill for authentication, authorization, or identity in a Cratis Arc project — backend, frontend, or both. Covers identity providers (`IProvideIdentityDetails`), protecting commands/queries with authorization attributes, Microsoft Identity Platform, connecting backend identity to React, multi-tenant identity, and local-dev generated principals. Trigger on auth, login, roles, permissions, identity details, user context, or protecting endpoints.
Install
npx vskill@latest install cratis/ai.distribution/auth-and-identitySKILL.md
The same SKILL.md was published earlier as cratis/ai.distribution/auth-and-identity.
Auth & Identity in Cratis Arc
This skill covers the full auth and identity stack in a Cratis Arc application. Read the relevant reference files below for detailed API usage.
Read the relevant instruction files first. This skill references concepts from the core copilot instructions in.github/copilot-instructions.md. If you need details on vertical slices, commands, queries, or proxy generation, consult those instructions.
Architecture Overview
Identity and auth in Arc follow a cookie-first, convention-based pattern:
Key design decisions:
- The
.cratis-identitycookie isHttpOnly=falseso the frontend JavaScript can read it directly — no extra HTTP call needed on page load. - Identity details are base64-encoded JSON in the cookie, automatically decoded by the frontend
IdentityProvider. - Only one
IProvideIdentityDetailsimplementation is allowed per application (auto-discovered). If none exists, a default provider grants access to everyone. - Cratis has its own
[Authorize],[AllowAnonymous], and[Roles]attributes inCratis.Arc.Authorization— these are distinct from ASP.NET Core's and are evaluated byAuthorizationEvaluatorin the command and query pipeline.
Decision Tree — Which Reference to Read
Use this decision tree to determine which reference file(s) to read based on the user's task:
| User wants to... | Read this reference | |
|---|---|---|
| Add identity details to their app | references/backend-identity.md | |
Customize IProvideIdentityDetails (enrich from DB, block users, multi-tenant, preferences) | references/backend-identity.md | |
Modify identity at runtime (stateless selections, ModifyDetails) | references/backend-identity.md | |
| Use Azure AD / Entra ID / Microsoft Identity | references/authentication.md | |
| Write a custom authentication handler (API key, JWT, etc.) | references/authentication.md | |
| Protect commands or queries with roles | references/authorization.md | |
Set up [Authorize], [AllowAnonymous], or [Roles] | references/authorization.md | |
| Consume identity in React | references/frontend.md | |
| Use identity in MVVM or vanilla TypeScript | references/frontend.md | |
| Test identity locally without Azure | references/local-development.md | |
| Full-stack setup (backend + frontend) | Read all references in order |
For full-stack tasks, read in this order:
references/backend-identity.md— identity provider and startupreferences/authentication.md— how users are authenticatedreferences/authorization.md— protecting commands and queriesreferences/frontend.md— consuming identity in the UIreferences/local-development.md— testing without real infrastructure
Quick-Start: Full-Stack Identity Setup
This is the minimum checklist for an application with identity. Read the reference files for details on each step.
Backend
- Details record: Define a C# record for application-specific user information
- Identity provider: Implement
IProvideIdentityDetails<TDetails>(auto-discovered, one per app) - Startup: Call
app.MapIdentityProvider()to registerGET /.cratis/me - Authentication: Add
AddMicrosoftIdentityPlatformIdentityAuthentication()or implementIAuthenticationHandler - Authorization: Add
[Authorize]/[Roles]/[AllowAnonymous]attributes fromCratis.Arc.Authorizationto commands and queries
Frontend
- Provider: Wrap app root with
<IdentityProvider>from@cratis/arc.react/identity - Hook: Use
useIdentity<TDetails>()to access identity anywhere in the component tree - Roles: Use
identity.isInRole('Admin')for UI-level role gating
Proxy Generation
- Using
IProvideIdentityDetails<TDetails>(generic) enables automatic TypeScript type generation atdotnet buildtime — the generated types can be imported in the frontend for end-to-end type safety.
Critical Rules
These rules are frequently violated — always enforce them:
- One identity provider per app: Only one
IProvideIdentityDetailsimplementation is allowed. Multiple throwsMultipleIdentityDetailsProvidersFound. - Use Cratis attributes, not ASP.NET Core's:
[Authorize],[Roles],[AllowAnonymous]must come fromCratis.Arc.Authorization, notMicrosoft.AspNetCore.Authorization. - Never combine `[Authorize]` and `[AllowAnonymous]` on the same target: This throws
AmbiguousAuthorizationLevel. - Prefer the generic interface: Use
IProvideIdentityDetails<TDetails>overIProvideIdentityDetailsto enable proxy generation. - Auto-discovery: Both
IProvideIdentityDetailsandIAuthenticationHandlerimplementations are auto-discovered — no DI registration needed. - Frontend role checks are UX, not security:
isInRole()on the frontend hides UI elements. The backend[Roles]attribute is the actual security boundary. - Build before frontend: TypeScript proxy types for identity details are generated by
dotnet build. The backend must compile before the frontend can import them. - Authorize at the boundary, secure by default: express access with
[Authorize]/[Roles]attributes on the command/query — never gate behavior with anif (identity.IsInRole(...))insideHandle(). For app-wide protection, configure a default-deny fallback policy so a target is protected unless it explicitly opts out with[AllowAnonymous]. Cross-cutting auth that spans many commands belongs in anICommandFilter, not duplicated per handler. - Command-specific scope is validation, not an attribute: a rule like "may only act on resources in your own organization" belongs in the
CommandValidator<T>(inject the identity and reject with a validation error) — not inHandle(), and not expressible by a role attribute alone. - Read the current user from the authenticated principal: in backend code resolve the current user from
IHttpContextAccessor.User(the ASP.NET principal the authentication handler populates). Do not invent a bespokeIIdentityAccessorabstraction — that is a product-specific wrapper, not part of generic Cratis.
Common Code Patterns
Protecting a command with roles
Conditionally rendering UI based on roles
Modifying identity at runtime (stateless selections)
Reference Documentation
Skill references (detailed implementation guidance)
- Backend Identity Provider —
IProvideIdentityDetails,IdentityProviderContext, cookie mechanics, proxy generation,ModifyDetails - Authentication —
IAuthenticationHandler,AuthenticationResult, Microsoft Identity Platform, combining handlers - Authorization —
[Authorize],[Roles],[AllowAnonymous], inheritance rules, fallback policies - Frontend Identity — React
IdentityProvider,useIdentity(), MVVM, core identity, role checking - Local Development — Generating principals, ModHeader, cookie fallback, dev testing
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/auth-and-identity/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
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/cratis/ai.distribution/auth-and-identity)