Fail closed on malformed local auth

This commit is contained in:
2026-04-11 16:29:53 +02:00
parent 6a223a4b70
commit 09e96ce381
6 changed files with 90 additions and 19 deletions
@@ -0,0 +1,17 @@
using System.Security.Claims;
namespace JobTrackerApi.Services;
public static class LocalAuthIdentity
{
public static string? GetRequiredUserId(ClaimsPrincipal? user)
{
if (user?.Identity?.IsAuthenticated != true)
{
return null;
}
var userId = user.FindFirstValue(ClaimTypes.NameIdentifier) ?? user.FindFirstValue("sub");
return string.IsNullOrWhiteSpace(userId) ? null : userId;
}
}