Sets up JWT authentication and authorization in ASP.NET Core, including token issuing, validation, refresh tokens, and policy-based roles. Also reviews existing auth setups.
Ships in TheCodeMan .NET AI ToolKit. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Wire up JWT bearer authentication and authorization in an ASP.NET Core API with secure defaults: token issuing, validation, refresh tokens, and policy-based authorization.
If they point at a project or repo, inspect the existing auth setup before changing anything:
git clone --depth 1 <url> /tmp/repo && cd /tmp/repoDiscover current state yourself, e.g.:
grep -rn "AddAuthentication\|AddJwtBearer\|TokenValidationParameters\|AddAuthorization\|RequireAuthorization\|RequireHttpsMetadata" --include=*.cs <target> | grep -vi "/obj/\|/bin/"
If auth already exists, review and harden it (validation flags, HTTPS metadata, ClockSkew, refresh-token handling, where the signing key lives) rather than re-adding from scratch, and flag any access-control gaps (endpoints without RequireAuthorization / no fallback policy).
The user wants to secure an API with JWTs, or wants their existing auth reviewed. If new: confirm whether they're issuing tokens themselves (own login) or validating tokens from an external IdP (Azure AD / Auth0 / Keycloak). Defaults below cover self-issued; for external IdP, the validation half is the same and issuing is delegated.
dotnet add package Microsoft.AspNetCore.Authentication.JwtBearer
dotnet add package System.IdentityModel.Tokens.Jwt
var jwt = builder.Configuration.GetSection("Jwt");
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = jwt["Issuer"],
ValidAudience = jwt["Audience"],
IssuerSigningKey = new SymmetricSecurityKey(
Encoding.UTF8.GetBytes(jwt["Key"]!)),
ClockSkew = TimeSpan.FromSeconds(30) // tighten the default 5 min
};
});
builder.Services.AddAuthorization(options =>
{
options.AddPolicy("AdminOnly", p => p.RequireRole("Admin"));
options.AddPolicy("CanManageOrders", p => p.RequireClaim("permission", "orders:manage"));
});
// ... after build:
app.UseAuthentication();
app.UseAuthorization();
public class TokenService(IConfiguration config)
{
public string CreateAccessToken(User user)
{
var jwt = config.GetSection("Jwt");
var claims = new List<Claim>
{
new(JwtRegisteredClaimNames.Sub, user.Id.ToString()),
new(JwtRegisteredClaimNames.Email, user.Email),
new(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
new(ClaimTypes.Role, user.Role)
};
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwt["Key"]!));
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
var token = new JwtSecurityToken(
issuer: jwt["Issuer"],
audience: jwt["Audience"],
claims: claims,
expires: DateTime.UtcNow.AddMinutes(15), // short-lived access token
signingCredentials: creds);
return new JwtSecurityTokenHandler().WriteToken(token);
}
}
Revoked flag — never just a JWT you can't revoke.app.MapGet("/orders", () => ...).RequireAuthorization();
app.MapPost("/orders", () => ...).RequireAuthorization("CanManageOrders");
app.MapDelete("/admin/{id}", () => ...).RequireAuthorization("AdminOnly");
// Reading the current user:
app.MapGet("/me", (ClaimsPrincipal user) =>
Results.Ok(new { Id = user.FindFirstValue(JwtRegisteredClaimNames.Sub) }))
.RequireAuthorization();
RequireHttpsMetadata = true in production.ClockSkew — the 5-minute default extends token lifetime by 5 minutes.[Authorize(Roles=...)] strings.## What I'm setting up
<self-issued vs external IdP, what's protected>
## Packages + Program.cs wiring
...
## Token issuing / refresh
...
## Config & secrets
<appsettings shape + where the key actually goes>
What SKILL.md sets; muted values are Claude Code's defaults
/dotnet-ai-toolkit:jwt-auth-setupfrom TheCodeMan .NET AI ToolKit
npx claudepluginhub stefanthecode/dotnet-ai-toolkit --plugin dotnet-ai-toolkit49 skills in this plugin
/adonet-data-access-auditorAudit and fix classic ADO.NET data-access code (SqlConnection / SqlCommand / SqlDataReader / DataSet) on .NET Framework. Use this skill whenever the user shares raw ADO.NET code, a DAL / repository built on SqlCommand, stored-proc calls, string-concatenated SQL, or mentions SQL injection, parameterized queries, connection leaks, "using / Dispose", reading the same column multiple times, transactions, or "why does my old data layer leak connections / is it safe". Always use this skill for classic ADO.NET review instead of answering from memory; it applies a fixed security + correctness + performance checklist and rewrites the code./async-await-auditorAudit C#/.NET code for async/await anti-patterns and concurrency bugs. Use this skill whenever the user shares async C# code or asks about deadlocks, async void, .Result/.Wait(), blocking calls, ConfigureAwait, sync-over-async, fire-and-forget tasks, CancellationToken usage, or "why does my async code hang/deadlock". Always use this skill for async correctness/performance reviews instead of answering from memory; it applies a fixed checklist and rewrites the code./authorization-policy-generatorDesign ASP.NET Core authorization — policy-based, role-based, and claims/requirement-based with custom authorization handlers and resource-based checks. Use this skill whenever the user wants authorization policies, role/claim checks, custom AuthorizationHandler, resource-based authorization, permission checks, or asks "how do I authorize this / policy vs role / restrict this endpoint to X". Always use this skill for authorization requests; it generates policies, handlers, and endpoint wiring./benchmarkdotnet-setupSet up BenchmarkDotNet for a .NET project and interpret the results — proper benchmark classes, memory diagnostics, baselines, and reading ns/op + allocations. Use this skill whenever the user wants to benchmark code, measure performance, compare two implementations, set up BenchmarkDotNet, or asks "which is faster / how do I benchmark this / interpret these benchmark results". Always use this skill for micro-benchmarking requests; it writes correct benchmarks and explains the numbers./caching-strategy-setupAdd the right caching to a .NET app — IMemoryCache, distributed cache, or HybridCache (.NET 9+) — with correct keys, expiration, stampede protection, and invalidation. Use this skill whenever the user wants caching, to cache a query/response, IMemoryCache, Redis/distributed cache, HybridCache, output caching, or asks "how do I cache this / add caching / avoid cache stampede". Always use this skill for caching requests; it picks the right layer and wires expiration + invalidation correctly./cicd-pipeline-generatorGenerate a CI/CD pipeline for a .NET app — GitHub Actions or Azure DevOps — with restore, build, test, coverage, vulnerability scan, container build, and deploy stages. Use this skill whenever the user wants a CI/CD pipeline, GitHub Actions workflow, Azure DevOps YAML, build/test automation, a release pipeline, or asks "how do I set up CI / pipeline for .NET / automate build and deploy". Always use this skill for CI/CD requests; it generates a complete, sensible pipeline.Other plugins' skills for the same job