protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, AccessRightRequirement requirement)
        {
            var data = context.User.Claims.FirstOrDefault(c => c.Type == "_UserId")?.Value;

            int             _UserId = 0, _CustomerId = 0;
            enmCustomerType _CustomerType = enmCustomerType.B2C;
            string          tempUserId    = context.User.Claims.FirstOrDefault(c => c.Type == "_UserId")?.Value;

            int.TryParse(tempUserId, out _UserId);

            string _Name          = context.User.Claims.FirstOrDefault(c => c.Type == "_Name")?.Value;
            string tempCustomerId = context.User.Claims.FirstOrDefault(c => c.Type == "_CustomerId")?.Value;

            int.TryParse(tempCustomerId, out _CustomerId);
            string tempCustomerType = context.User.Claims.FirstOrDefault(c => c.Type == "_CustomerType")?.Value;

            if (!string.IsNullOrEmpty(tempCustomerType))
            {
                Enum.TryParse <enmCustomerType>(tempCustomerType, out _CustomerType);
            }

            _currentUser.CustomerId   = _CustomerId;
            _currentUser.UserId       = _UserId;
            _currentUser.CustomerType = _CustomerType;
            _currentUser.Name         = _Name;

            if (_currentUser.HaveClaim(requirement.accessRight))
            {
                context.Succeed(requirement);
            }
            return(Task.CompletedTask);
        }
Beispiel #2
0
 protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, AccessRightRequirement requirement)
 {
     if (_currentUser.HaveClaim(requirement.accessRight))
     {
         context.Succeed(requirement);
     }
     return(Task.CompletedTask);
 }