cad-todo-api-auth

Adds JWT authentication and per-user authorization to an ASP.NET Core TODO API.

2|Updated Jun 1, 2026
One-click install
npx skills add https://github.com/jay-steenbergen/MSSAMentorAgent --skill cad-todo-api-auth-jay-steenbergen
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cad-todo-api-auth
Source: https://github.com/jay-steenbergen/MSSAMentorAgent/tree/main/.github/skills/tracks/cloud-app-dev/cad-todo-api-auth
Command: npx skills add https://github.com/jay-steenbergen/MSSAMentorAgent --skill cad-todo-api-auth-jay-steenbergen

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Learners who have built a basic ASP.NET Core TODO API often struggle to understand how to secure it, especially the difference between authentication and authorization. This Skill provides a structured, five-phase build recipe that turns an unsecured EF Core API into a JWT-protected API with per-user data scoping. ## Core Features & Use Cases - JWT Authentication Setup: Guides installing Microsoft.AspNetCore.Authentication.JwtBearer, configuring TokenValidationParameters, and ordering authentication/authorization middleware correctly in Program.cs. - Login Endpoint and Token Issuance: Builds a POST /auth/login controller that validates credentials and returns signed JWTs with claims and expiry. - Endpoint and Data Protection: Applies [Authorize] filters and OwnerId-based data scoping with EF Core migrations so each user only sees their own TODOs, including an explanation of IDOR vulnerabilities. - Use Case: A mentor teaching a learner who finished an EF-backed TODO API uses this recipe to add login, protect endpoints, and run a two-user smoke test proving 401 for anonymous calls and row-level isolation between users. ## Quick Start Ask the mentor to start the cad-todo-api-auth project to add JWT login and per-user TODO authorization to your existing EF Core TODO API.

Frequently Asked Questions about cad-todo-api-auth

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

FAQPage Schema
How do I add JWT authentication to an ASP.NET Core API?

Install the Microsoft.AspNetCore.Authentication.JwtBearer package, add a Jwt section with issuer, audience, and a 32+ character signing key to appsettings.json, then register AddAuthentication().AddJwtBearer() with TokenValidationParameters in Program.cs. Call UseAuthentication before UseAuthorization, both before MapControllers.

What is the difference between authentication and authorization in ASP.NET Core?

Authentication proves who you are, typically by validating a JWT bearer token. Authorization checks what you are allowed to do, using [Authorize] attributes or data scoping. ASP.NET Core runs separate middleware for each, and authentication must run first.

Why does my JWT-protected endpoint return 401 Unauthorized?

A 401 means the request has no token, an invalid token, or an expired token. Common causes are a signing key shorter than 32 characters, middleware registered in the wrong order, malformed appsettings.json, or forgetting to send the Authorization: Bearer header.

How do I restrict users to only their own data in ASP.NET Core?

Add an OwnerId column to your model with an EF Core migration, read the user id from User.FindFirstValue in the controller, and filter queries with Where(t => t.OwnerId == currentUserId). Also set OwnerId on POST so new rows belong to the caller.

Why is User.FindFirstValue("sub") returning null after JWT login?

By default .NET 8 rewrites short claim names like sub into long ClaimTypes URIs. Call JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear() before registering JWT bearer auth so the sub claim is preserved as issued.

Is hardcoding users with plain-text passwords in appsettings.json acceptable?

Only for a scoped tutorial focused on token mechanics. Production systems require ASP.NET Core Identity, hashed passwords with BCrypt or Argon2, refresh tokens, and an identity provider such as Entra ID or Auth0, with secrets stored outside source control.