Fail closed on malformed local auth
This commit is contained in:
@@ -16,14 +16,5 @@ public sealed class CurrentUserService : ICurrentUserService
|
||||
_http = http;
|
||||
}
|
||||
|
||||
public string? UserId
|
||||
{
|
||||
get
|
||||
{
|
||||
var u = _http.HttpContext?.User;
|
||||
if (u is null) return null;
|
||||
if (u.Identity?.IsAuthenticated != true) return null;
|
||||
return u.FindFirstValue(ClaimTypes.NameIdentifier) ?? u.FindFirstValue("sub");
|
||||
}
|
||||
}
|
||||
public string? UserId => LocalAuthIdentity.GetRequiredUserId(_http.HttpContext?.User);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user