Beispiel #1
0
        public Task <IdentityAdminResult <CreateResult> > CreateAsync(IEnumerable <PropertyValue> properties)
        {
            var ApiResourceNameClaim = properties.Single(x => x.Type == "ApiResourceName");

            var ApiResourceName = ApiResourceNameClaim.Value;

            string[] exclude         = { "ApiResourceName" };
            var      otherProperties = properties.Where(x => !exclude.Contains(x.Type)).ToArray();

            var metadata            = GetMetadata();
            var createProps         = metadata.CreateProperties;
            var inMemoryApiResource = new InMemoryApiResource
            {
                Id      = _apiResources.Count + 1,
                Name    = ApiResourceName,
                Enabled = true
            };

            foreach (var prop in otherProperties)
            {
                var propertyResult = SetProperty(createProps, inMemoryApiResource, prop.Type, prop.Value);
                if (!propertyResult.IsSuccess)
                {
                    return(Task.FromResult(new IdentityAdminResult <CreateResult>(propertyResult.Errors.ToArray())));
                }
            }
            _apiResources.Add(inMemoryApiResource);
            return(Task.FromResult(new IdentityAdminResult <CreateResult>(new CreateResult {
                Subject = inMemoryApiResource.Id.ToString()
            })));
        }
Beispiel #2
0
        protected string GetProperty(PropertyMetadata propMetadata, InMemoryApiResource apiResource)
        {
            string val;

            if (propMetadata.TryGet(apiResource, out val))
            {
                return(val);
            }
            throw new Exception("Invalid property type " + propMetadata.Type);
        }
Beispiel #3
0
        protected IdentityAdminResult SetProperty(IEnumerable <PropertyMetadata> propsMeta, InMemoryApiResource apiResource, string type, string value)
        {
            IdentityAdminResult result;

            if (propsMeta.TrySet(apiResource, type, value, out result))
            {
                return(result);
            }

            throw new Exception("Invalid property type " + type);
        }