15 lines
633 B
C#
15 lines
633 B
C#
using System.Security.Claims;
|
|
namespace PlotLine.Services;
|
|
|
|
// Shared with the existing AdminOnly policy; a role/name alone never grants access.
|
|
public static class AdministratorAccess
|
|
{
|
|
public static bool IsAllowed(ClaimsPrincipal? user, IConfiguration configuration)
|
|
{
|
|
if (user?.Identity?.IsAuthenticated != true) return false;
|
|
var email = user.FindFirstValue(ClaimTypes.Email);
|
|
return !string.IsNullOrWhiteSpace(email) && (configuration.GetSection("Admin:AllowedEmails").Get<string[]>() ?? [])
|
|
.Any(allowed => string.Equals(allowed, email, StringComparison.OrdinalIgnoreCase));
|
|
}
|
|
}
|