using System; using System.Linq; using System.Security.Claims; namespace Infrastructure.Extensions { public static class ClaimsPrincipalExtensions { public static bool IsInRole(this ClaimsPrincipal user, object role) { if (user is null) { throw new System.ArgumentNullException(nameof(user)); } return role == null ? false : user.IsInRole(role.ToString()); } public static Guid? GetOrganId(this ClaimsPrincipal user) { var value = user.Claims.FirstOrDefault(o => o.Type == "OrganId")?.Value; return Guid.TryParse(value, out Guid id) ? id : null; } } }