Esempio n. 1
0
        private void ValidateClaims(User user)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            if (user.Claims == null)
            {
                return;
            }
            var claims = _claimsService.All();

            foreach (var item in user.Claims)
            {
                var exist = claims.SingleOrDefault(c => c.ResourcePath == item.ResourcePath);
                if (exist == null)
                {
                    throw new ClaimsException($"Claims not found for resource path {item.ResourcePath}");
                }

                var exclude = item.Scopes.Except(exist.Scopes);
                if (!exclude.Any())
                {
                    continue;
                }
                var invalidScopes = exclude.Select(s => s.ToString()).Aggregate(
                    (a, b) => a + "," + b);
                throw new ClaimsException($"Scopes {item} not valid for resource path {invalidScopes}");
            }
        }
 public IActionResult Get()
 {
     try
     {
         var dto = _mapper.Map <List <Claim>, List <ClaimResponseModel> >(_claimsService.All().ToList());
         return(Ok(dto));
     }
     catch (Exception e)
     {
         return(StatusCode((int)HttpStatusCode.InternalServerError, new ErrorModelInternalError(e)));
     }
 }