Beispiel #1
0
 private IEnumerable <object> GetScopes(ApiResourceDetail apiResource, UrlHelper url)
 {
     if (apiResource.ResourceScopes != null)
     {
         return(from c in apiResource.ResourceScopes
                select new
         {
             Data = c,
             Claims = GetScopeClaims(apiResource, c, url),
             Links = new
             {
                 update = url.RelativeLink(Constants.RouteNames.UpdateApiResourceScope, new
                 {
                     subject = apiResource.Subject,
                     id = c.Id
                 }),
                 delete = url.RelativeLink(Constants.RouteNames.RemoveApiResourceScope, new
                 {
                     subject = apiResource.Subject,
                     id = c.Id
                 }),
                 addClaim = url.RelativeLink(Constants.RouteNames.AddApiResourceScopeClaim, new
                 {
                     subject = apiResource.Subject,
                     id = c.Id
                 })
             }
         });
     }
     return(new object[0]);
 }
Beispiel #2
0
 private IEnumerable <object> GetSecrets(ApiResourceDetail apiResource, UrlHelper url)
 {
     if (apiResource.ResourceSecrets != null)
     {
         return(from c in apiResource.ResourceSecrets
                select new
         {
             Data = c,
             Links = new
             {
                 update = url.RelativeLink(Constants.RouteNames.UpdateApiResourceSecret, new
                 {
                     subject = apiResource.Subject,
                     id = c.Id
                 }),
                 delete = url.RelativeLink(Constants.RouteNames.RemoveApiResourceSecret, new
                 {
                     subject = apiResource.Subject,
                     id = c.Id
                 })
             }
         });
     }
     return(new object[0]);
 }
        public ApiResourceDetailResource(ApiResourceDetail apiResource, UrlHelper url, ApiResourceMetaData metaData)
        {
            if (apiResource == null)
            {
                throw new ArgumentNullException(nameof(apiResource));
            }
            if (url == null)
            {
                throw new ArgumentNullException(nameof(url));
            }
            if (metaData == null)
            {
                throw new ArgumentNullException(nameof(metaData));
            }

            Data = new ApiResourceDetailDataResource(apiResource, url, metaData);

            var links = new Dictionary <string, string>();

            if (metaData.SupportsDelete)
            {
                links["Delete"] = url.RelativeLink(Constants.RouteNames.DeleteApiResource, new { subject = apiResource.Subject });
            }
            Links = links;
        }
Beispiel #4
0
        public Task <IdentityAdminResult <ApiResourceDetail> > GetAsync(string subject)
        {
            int parsedId;

            if (int.TryParse(subject, out parsedId))
            {
                var inMemoryApiResource = _apiResources.FirstOrDefault(p => p.Id == parsedId);
                if (inMemoryApiResource == null)
                {
                    return(Task.FromResult(new IdentityAdminResult <ApiResourceDetail>((ApiResourceDetail)null)));
                }

                var result = new ApiResourceDetail
                {
                    Subject     = subject,
                    Name        = inMemoryApiResource.Name,
                    Description = inMemoryApiResource.Description
                };

                var metadata = GetMetadata();
                var props    = from prop in metadata.UpdateProperties
                               select new PropertyValue
                {
                    Type  = prop.Type,
                    Value = GetProperty(prop, inMemoryApiResource),
                };

                result.Properties     = props.ToArray();
                result.ResourceClaims = inMemoryApiResource.Claims.Select(x => new ApiResourceClaimValue
                {
                    Id   = x.Id.ToString(),
                    Type = x.Type
                });
                result.ResourceSecrets = inMemoryApiResource.Secrets.Select(x => new ApiResourceSecretValue
                {
                    Id          = x.Id.ToString(),
                    Type        = x.Type,
                    Description = x.Description,
                    Value       = x.Value,
                    Expiration  = x.Expiration
                });
                result.ResourceScopes = inMemoryApiResource.Scopes.Select(x => new ApiResourceScopeValue
                {
                    Id                      = x.Id.ToString(),
                    Name                    = x.Name,
                    Description             = x.Description,
                    Emphasize               = x.Emphasize,
                    Required                = x.Required,
                    ShowInDiscoveryDocument = x.ShowInDiscoveryDocument,
                    Claims                  = x.Claims.Select(y => new ApiResourceScopeClaimValue
                    {
                        Id   = y.Id.ToString(),
                        Type = y.Type
                    })
                });

                return(Task.FromResult(new IdentityAdminResult <ApiResourceDetail>(result)));
            }
            return(Task.FromResult(new IdentityAdminResult <ApiResourceDetail>((ApiResourceDetail)null)));
        }
Beispiel #5
0
 private IEnumerable <object> GetClaims(ApiResourceDetail apiResource, UrlHelper url)
 {
     if (apiResource.ResourceClaims != null)
     {
         return(from c in apiResource.ResourceClaims.ToArray()
                select new
         {
             Data = c,
             Links = new
             {
                 delete = url.RelativeLink(Constants.RouteNames.RemoveApiResourceClaim, new
                 {
                     subject = apiResource.Subject,
                     id = c.Id
                 })
             }
         });
     }
     return(new object[0]);
 }
Beispiel #6
0
 private IEnumerable <object> GetScopeClaims(ApiResourceDetail apiResource, ApiResourceScopeValue apiResourceScope, IUrlHelper url)
 {
     if (apiResourceScope.Claims != null)
     {
         return(from c in apiResourceScope.Claims
                select new
         {
             Data = c,
             Links = new
             {
                 delete = url.RelativeLink(Constants.RouteNames.RemoveApiResourceScopeClaim, new
                 {
                     subject = apiResource.Subject,
                     id = apiResourceScope.Id,
                     claimId = c.Id
                 })
             }
         });
     }
     return(new object[0]);
 }
Beispiel #7
0
        public ApiResourceDetailDataResource(ApiResourceDetail apiResource, UrlHelper url, ApiResourceMetaData metaData)
        {
            if (apiResource == null)
            {
                throw new ArgumentNullException(nameof(apiResource));
            }
            if (url == null)
            {
                throw new ArgumentNullException(nameof(url));
            }
            if (metaData == null)
            {
                throw new ArgumentNullException(nameof(metaData));
            }

            this["Name"]        = apiResource.Name;
            this["Description"] = apiResource.Description;
            this["Subject"]     = apiResource.Subject;

            if (apiResource.Properties != null)
            {
                var props = (from p in apiResource.Properties
                             let m = (from m in metaData.UpdateProperties where m.Type == p.Type select m).SingleOrDefault()
                                     where m != null
                                     select new
                {
                    Data = m.Convert(p.Value),
                    Meta = m,
                    Links = new
                    {
                        update = url.RelativeLink(Constants.RouteNames.UpdateApiResourceProperty,
                                                  new
                        {
                            subject = apiResource.Subject,
                            type = p.Type.ToBase64UrlEncoded()
                        }
                                                  )
                    }
                }).ToList();

                if (props.Any())
                {
                    this["Properties"] = props.ToArray();
                }
            }

            this["Claims"] = new
            {
                Data  = GetClaims(apiResource, url).ToArray(),
                Links = new
                {
                    create = url.RelativeLink(Constants.RouteNames.AddApiResourceClaim, new { subject = apiResource.Subject })
                }
            };

            this["Secrets"] = new
            {
                Data  = GetSecrets(apiResource, url).ToArray(),
                Links = new
                {
                    create = url.RelativeLink(Constants.RouteNames.AddApiResourceSecret, new { subject = apiResource.Subject })
                }
            };

            this["Scopes"] = new
            {
                Data  = GetScopes(apiResource, url).ToArray(),
                Links = new
                {
                    create = url.RelativeLink(Constants.RouteNames.AddApiResourceScope, new { subject = apiResource.Subject })
                }
            };
        }