Пример #1
0
        protected string GetClientProperty(PropertyMetadata propMetadata, InMemoryClient client)
        {
            string val;

            if (propMetadata.TryGet(client, out val))
            {
                return(val);
            }
            throw new Exception("Invalid property type " + propMetadata.Type);
        }
Пример #2
0
        public static ICollection<InMemoryClient> Get(int random = 0)
        {
            var clients = new HashSet<InMemoryClient>
            {
                new InMemoryClient{
                    ClientId = "IdentityAdminClientUniqueId",
                    ClientName = "Indentity Admin Client",
                    Enabled = true,
                    Flow = Flows.Implicit,
                    RequireConsent = true,
                    AllowRememberConsent = true,
                    AllowedScopes = new List<InMemoryClientScope>
                    {
                        new InMemoryClientScope
                        {
                            Id = 1,
                            Scope =  "openid",
                        },
                        new InMemoryClientScope
                        {
                            Id = 2,
                            Scope =  "profile",
                        },
                        new InMemoryClientScope
                        {
                            Id = 3,
                            Scope =  "email",
                        },
                    },
                    AccessTokenType = AccessTokenType.Jwt
                }
            };

            for (var i = 0; i < random; i++)
            {
                var client = new InMemoryClient
                {
                    ClientName = GenName().ToLower(),
                    ClientId = GenName().ToLower(),
                    Id = clients.Count + 1,
                    
                };

                clients.Add(client);
            }

            return clients;

        }
Пример #3
0
        public static ICollection <InMemoryClient> Get(int random = 0)
        {
            var clients = new HashSet <InMemoryClient>
            {
                new InMemoryClient {
                    ClientId             = "IdentityAdminClientUniqueId",
                    ClientName           = "Indentity Admin Client",
                    Enabled              = true,
                    Flow                 = Flows.Implicit,
                    RequireConsent       = true,
                    AllowRememberConsent = true,
                    AllowedScopes        = new List <InMemoryClientScope>
                    {
                        new InMemoryClientScope
                        {
                            Id    = 1,
                            Scope = "openid",
                        },
                        new InMemoryClientScope
                        {
                            Id    = 2,
                            Scope = "profile",
                        },
                        new InMemoryClientScope
                        {
                            Id    = 3,
                            Scope = "email",
                        },
                    },
                    AccessTokenType = AccessTokenType.Jwt
                }
            };

            for (var i = 0; i < random; i++)
            {
                var client = new InMemoryClient
                {
                    ClientName = GenName().ToLower(),
                    ClientId   = GenName().ToLower(),
                    Id         = clients.Count + 1,
                };

                clients.Add(client);
            }

            return(clients);
        }
Пример #4
0
        public Task <IdentityAdminResult <CreateResult> > CreateClientAsync(IEnumerable <PropertyValue> properties)
        {
            var clientNameClaim = properties.Single(x => x.Type == "ClientName");
            var clientIdClaim   = properties.Single(x => x.Type == "ClientId");

            var clientId   = clientNameClaim.Value;
            var clientName = clientIdClaim.Value;

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

            var metadata       = GetMetadata();
            var createProps    = metadata.ClientMetaData.CreateProperties;
            var client         = new Client();
            var inMemoryClient = new InMemoryClient
            {
                ClientId   = clientId,
                ClientName = clientName,
                Id         = _clients.Count + 1,
                AbsoluteRefreshTokenLifetime = client.AbsoluteRefreshTokenLifetime,
                AccessTokenLifetime          = client.AccessTokenLifetime,
                IdentityTokenLifetime        = client.IdentityTokenLifetime,
                SlidingRefreshTokenLifetime  = client.SlidingRefreshTokenLifetime,
                Enabled          = true,
                EnableLocalLogin = true,
            };

            foreach (var prop in otherProperties)
            {
                var propertyResult = SetClientProperty(createProps, inMemoryClient, prop.Type, prop.Value);
                if (!propertyResult.IsSuccess)
                {
                    return(Task.FromResult(new IdentityAdminResult <CreateResult>(propertyResult.Errors.ToArray())));
                }
            }

            _clients.Add(inMemoryClient);
            return
                (Task.FromResult(
                     new IdentityAdminResult <CreateResult>(new CreateResult {
                Subject = inMemoryClient.Id.ToString()
            })));
        }
Пример #5
0
        protected IdentityAdminResult SetClientProperty(IEnumerable <PropertyMetadata> propsMeta, InMemoryClient client,
                                                        string type, string value)
        {
            IdentityAdminResult result;

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

            throw new Exception("Invalid property type " + type);
        }
 protected string GetClientProperty(PropertyMetadata propMetadata, InMemoryClient client)
 {
     string val;
     if (propMetadata.TryGet(client, out val))
     {
         return val;
     }
     throw new Exception("Invalid property type " + propMetadata.Type);
 }
        protected IdentityAdminResult SetClientProperty(IEnumerable<PropertyMetadata> propsMeta, InMemoryClient client,
            string type, string value)
        {
            IdentityAdminResult result;
            if (propsMeta.TrySet(client, type, value, out result))
            {
                return result;
            }

            throw new Exception("Invalid property type " + type);
        }
        public Task<IdentityAdminResult<CreateResult>> CreateClientAsync(IEnumerable<PropertyValue> properties)
        {
            var clientNameClaim = properties.Single(x => x.Type == "ClientName");
            var clientIdClaim = properties.Single(x => x.Type == "ClientId");

            var clientId = clientNameClaim.Value;
            var clientName = clientIdClaim.Value;

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

            var metadata = GetMetadata();
            var createProps = metadata.ClientMetaData.CreateProperties;
            var client  = new Client();
            var inMemoryClient = new InMemoryClient
            {
                ClientId = clientId,
                ClientName = clientName,
                Id = _clients.Count + 1,
                AbsoluteRefreshTokenLifetime = client.AbsoluteRefreshTokenLifetime,
                AccessTokenLifetime = client.AccessTokenLifetime,
                IdentityTokenLifetime = client.IdentityTokenLifetime,
                SlidingRefreshTokenLifetime = client.SlidingRefreshTokenLifetime,
                Enabled =  true,
                EnableLocalLogin =  true,

            };

            foreach (var prop in otherProperties)
            {
                var propertyResult = SetClientProperty(createProps, inMemoryClient, prop.Type, prop.Value);
                if (!propertyResult.IsSuccess)
                {
                    return Task.FromResult(new IdentityAdminResult<CreateResult>(propertyResult.Errors.ToArray()));
                }
            }

            _clients.Add(inMemoryClient);
            return
                Task.FromResult(
                    new IdentityAdminResult<CreateResult>(new CreateResult {Subject = inMemoryClient.Id.ToString()}));
        }