DeutschLernen/GermanApp
Lasse Rune Hansen f1ed8a1a7a
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
fix(backend/auth): Fix JWT claim mapping issue causing 401 on /me endpoint
PROBLEM:
- Login returns JWT token with 'sub' claim
- /me endpoint tries to read user ID from JWT
- Gets 401 Unauthorized because user ID claim cannot be found

ROOT CAUSE:
ASP.NET Core JWT middleware automatically maps JWT standard claims to .NET claim types:
- JwtRegisteredClaimNames.Sub ('sub') -> ClaimTypes.NameIdentifier ('http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier')

Controllers were looking for 'sub' or 'nameid' but JWT middleware creates the claim with the full URI.

SOLUTION:
Updated all controllers to use ClaimTypes.NameIdentifier with fallback to 'sub':
- AuthController.GetCurrentUser()
- AdminController.DeleteUserAsync()
- StoryController.GetUserId()

This ensures the user ID can be found regardless of how the JWT middleware maps the claims.

CHANGES:
- AuthService: Generates JWT tokens with JwtRegisteredClaimNames.Sub (JWT standard)
- AuthController: Uses ClaimTypes.NameIdentifier ?? 'sub' fallback
- AdminController: Uses ClaimTypes.NameIdentifier ?? 'sub' fallback
- StoryController: Uses ClaimTypes.NameIdentifier ?? 'sub' fallback
- LessonsEndpoints.cs: Added .RequireAuthorization() to all GET endpoints
- docs/features/admin-module.md: Updated acceptance criteria and requirements
- Added unit tests in JwtTokenValidationTests.cs to verify the fix

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-06-14 18:25:49 +02:00
..
Application feat(backend): Implement mandatory authentication and admin module 2026-06-14 12:42:15 +02:00
Domain fix(backend/auth): Fix authentication bugs 2026-06-14 16:40:01 +02:00
Infrastructure fix(backend/auth): Fix JWT token claim mapping for user ID 2026-06-14 17:38:27 +02:00
Presentation fix(backend/auth): Fix JWT claim mapping issue causing 401 on /me endpoint 2026-06-14 18:25:49 +02:00
Properties Initial commit: GermanApp with Clean Architecture 2026-05-31 18:14:51 +02:00
Shared feat(backend/infra): add health checks, CORS, Serilog logging, and exception middleware 2026-05-31 19:52:00 +02:00
.dockerignore feat(backend/infra): add Docker configuration for Phase 3 2026-06-05 11:46:27 +02:00
Dockerfile fix(infra): remove problematic health checks for now 2026-06-05 13:03:10 +02:00
GermanApp.csproj feat(backend/infrastructure): implement Mistral API Connector (Phase 0 of AI Services) 2026-06-09 18:56:37 +02:00
GermanApp.http Initial commit: GermanApp with Clean Architecture 2026-05-31 18:14:51 +02:00
Program.cs fix(backend/auth): Fix authentication bugs 2026-06-14 16:40:01 +02:00