18 lines
451 B
C#
18 lines
451 B
C#
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;
|
|
}
|
|
}
|