Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
25 lines (23 sloc) 950 Bytes
// Copyright (c) 2018 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/
// Licensed under MIT license. See License.txt in the project root for license information.
using System.Linq;
using System.Security.Claims;
using PermissionParts;
namespace RolesToPermission
{
public static class PermissionExtensions
{
/// <summary>
/// This returns true if the current user has the permission
/// </summary>
/// <param name="user"></param>
/// <param name="permission"></param>
/// <returns></returns>
public static bool UserHasThisPermission(this ClaimsPrincipal user, Permissions permission)
{
var permissionClaim =
user?.Claims.SingleOrDefault(x => x.Type == PermissionConstants.PackedPermissionClaimType);
return permissionClaim?.Value.UnpackPermissionsFromString().Contains(permission) == true;
}
}
}