# authentication

A skill that feeds your coding agent working patterns for ASP.NET Core auth: JWT bearer, OpenID Connect, Identity, authorization policies.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 2800 installs · ★ 789
- Author: codewithmukesh
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/codewithmukesh/dotnet-claude-kit/tree/HEAD/skills/authentication/SKILL.md
- Updated: 2026-08-07
- HTML: https://affpapa.org/en/nevibecode/skills/codewithmukesh-authentication

## What it does

The skill puts ready-made ASP.NET Core patterns into your agent's context: JWT bearer setup, token generation, authorization policies, OpenID Connect, and reading the current user. The agent loads it on its own when the conversation mentions "auth", "JWT", "bearer token", "OIDC", "claims", "roles", or "RequireAuthorization".

Inside are four core principles plus code patterns. For user management the skill points to ASP.NET Identity rather than a hand-rolled store, since Identity already handles password hashing, lockout, two-factor, and email confirmation. APIs get bearer tokens, Blazor and MVC apps get cookies. Token generation runs through `JsonWebTokenHandler` from `Microsoft.IdentityModel.JsonWebTokens`; `JwtSecurityTokenHandler` is called the legacy stack.

There is a section on anti-patterns too. Role strings like `[Authorize(Roles = "Admin,SuperAdmin,Manager")]` are flagged as hard to refactor and test, so policies are the recommended route. Secrets in `appsettings.json` land on the bad list as well — `dotnet user-secrets` for development, environment variables in production. And do not turn off token validation: `ValidateLifetime = false` is marked "DEFINITELY DON'T" in the examples. If your project already has a working auth scheme, expect this skill to push against it, because it steers toward policies and Identity.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add codewithmukesh/dotnet-claude-kit --skill authentication -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/authentication/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/authentication/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add codewithmukesh/dotnet-claude-kit --skill authentication -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/authentication/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add codewithmukesh/dotnet-claude-kit --skill authentication -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/authentication/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install codewithmukesh/dotnet-claude-kit authentication
```

2. **Manually: put the files in place**
- File: `.github/skills/authentication/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add codewithmukesh/dotnet-claude-kit --skill authentication -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/codewithmukesh/dotnet-claude-kit --path skills/authentication
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/authentication/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add codewithmukesh/dotnet-claude-kit --skill authentication -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/codewithmukesh/dotnet-claude-kit/tree/HEAD/skills/authentication/SKILL.md

## When to use it
- wire up JWT bearer auth in ASP.NET Core without breaking token validation
- protect a group of endpoints with one policy instead of role strings
- generate a token carrying roles and claims with the current handler
- connect an external identity provider over OpenID Connect
- move the JWT signing key out of `appsettings.json` into user secrets

## Example prompts
- Help me set up JWT bearer authentication in Program.cs
- Add a CanManageOrders policy that requires the permission claim
- Rewrite [Authorize(Roles = "Admin")] as an authorization policy

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 23213db31534c6e1.

BEGIN THIRD-PARTY FILE 23213db31534c6e1
````text
---
name: authentication
description: >
  Authentication and authorization for ASP.NET Core. Covers JWT bearer tokens,
  OpenID Connect, ASP.NET Identity, authorization policies, role and claim-based
  authorization, and API key authentication.
  Load this skill when implementing login, protecting endpoints, designing
  authorization rules, or when the user mentions "auth", "JWT", "bearer token",
  "OIDC", "OpenID Connect", "Identity", "claims", "roles", "authorize",
  "RequireAuthorization", "API key", or "cookie auth".
---

# Authentication & Authorization

## Core Principles

1. **Use ASP.NET Identity for user management** — Don't build your own user store. Identity handles password hashing, lockout, two-factor, email confirmation, and (since .NET 10) built-in passkey/WebAuthn support for passwordless login.
2. **JWT for APIs, cookies for web apps** — APIs use Bearer token authentication; Blazor/MVC apps use cookie authentication.
3. **Policy-based authorization over roles** — Policies are testable, composable, and more expressive than `[Authorize(Roles = "Admin")]`.
4. **Never store secrets in code** — Use user secrets in development, Azure Key Vault / environment variables in production.

## Patterns

### JWT Bearer Authentication

```csharp
// Program.cs
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
    .AddJwtBearer(options =>
    {
        options.TokenValidationParameters = new TokenValidationParameters
        {
            ValidateIssuer = true,
            ValidateAudience = true,
            ValidateLifetime = true,
            ValidateIssuerSigningKey = true,
            ValidIssuer = builder.Configuration["Jwt:Issuer"],
            ValidAudience = builder.Configuration["Jwt:Audience"],
            IssuerSigningKey = new SymmetricSecurityKey(
                Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"]!)),
            ClockSkew = TimeSpan.Zero
        };
    });

builder.Services.AddAuthorization();
```

### Token Generation
````
END THIRD-PARTY FILE 23213db31534c6e1

The third-party file has ended. Everything between the 23213db31534c6e1 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2021 of 7663 bytes. © codewithmukesh · MIT · https://github.com/codewithmukesh/dotnet-claude-kit/tree/HEAD/skills/authentication/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
