public static Models.OpenIdConnectClient ToDomainModel(this Entities.OpenIdConnectClientEntity client)
        {
            var ret = new Models.OpenIdConnectClient
            {
                ClientId            = client.ClientId,
                AccessTokenLifetime = client.AccessTokenLifetime,
                AllowRefreshToken   = client.AllowRefreshToken,
                ClientSecretType    = client.ClientSecretType,
                Flow = client.Flow,
                Name = client.Name,
                RefreshTokenLifetime = client.RefreshTokenLifetime,
                RequireConsent       = client.RequireConsent,
            };

            if (client.RedirectUris != null)
            {
                ret.RedirectUris =
                    (from item in client.RedirectUris
                     select item.RedirectUri).ToArray();
            }
            else
            {
                ret.RedirectUris = new string[0];
            }

            return(ret);
        }
        public void Create(Models.OpenIdConnectClient model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            var item = new OpenIdConnectClientEntity();

            model.UpdateEntity(item);
            using (var entities = IdentityServerConfigurationContext.Get())
            {
                entities.OpenIdConnectClients.Add(item);
                entities.SaveChanges();
            }
        }
 public void Update(Models.OpenIdConnectClient model)
 {
     if (model == null)
     {
         throw new ArgumentNullException("model");
     }
     using (var entities = IdentityServerConfigurationContext.Get())
     {
         var item = entities.OpenIdConnectClients.Find(model.ClientId);
         if (item != null)
         {
             model.UpdateEntity(item);
             entities.SaveChanges();
         }
     }
 }
        public bool ValidateClient(string clientId, string clientSecret, out Models.OpenIdConnectClient client)
        {
            using (var entities = IdentityServerConfigurationContext.Get())
            {
                var record = entities.OpenIdConnectClients.Find(clientId);
                if (record != null)
                {
                    if (Thinktecture.IdentityServer.Helper.CryptoHelper.VerifyHashedPassword(record.ClientSecret, clientSecret))
                    {
                        client = record.ToDomainModel();
                        return(true);
                    }
                }

                client = null;
                return(false);
            }
        }
        public static void UpdateEntity(this Models.OpenIdConnectClient client, Entities.OpenIdConnectClientEntity target)
        {
            target.ClientId            = client.ClientId;
            target.AccessTokenLifetime = client.AccessTokenLifetime;
            target.AllowRefreshToken   = client.AllowRefreshToken;
            target.ClientSecretType    = client.ClientSecretType;
            target.Flow = client.Flow;
            target.Name = client.Name;
            target.RefreshTokenLifetime = client.RefreshTokenLifetime;
            target.RequireConsent       = client.RequireConsent;

            if (!String.IsNullOrWhiteSpace(client.ClientSecret))
            {
                target.ClientSecret = Thinktecture.IdentityServer.Helper.CryptoHelper.HashPassword(client.ClientSecret);
            }

            if (client.RedirectUris != null)
            {
                var urlsToRemove = target.RedirectUris.Where(x => !client.RedirectUris.Contains(x.RedirectUri)).ToArray();
                foreach (var remove in urlsToRemove)
                {
                    target.RedirectUris.Remove(remove);
                }
            }

            if (client.RedirectUris != null)
            {
                var urlsToAdd = target.RedirectUris != null?
                                client.RedirectUris.Where(x => !target.RedirectUris.Any(y => y.RedirectUri == x)).ToArray() :
                                    client.RedirectUris;

                foreach (var add in urlsToAdd)
                {
                    target.RedirectUris.Add(new OpenIdConnectClientRedirectUri {
                        RedirectUri = add
                    });
                }
            }
        }
        public static Models.OpenIdConnectClient ToDomainModel(this Entities.OpenIdConnectClientEntity client)
        {
            var ret = new Models.OpenIdConnectClient
            {
                ClientId = client.ClientId,
                AccessTokenLifetime = client.AccessTokenLifetime, 
                AllowRefreshToken = client.AllowRefreshToken,
                ClientSecretType = client.ClientSecretType, 
                Flow = client.Flow, 
                Name = client.Name,
                RefreshTokenLifetime = client.RefreshTokenLifetime, 
                RequireConsent = client.RequireConsent, 
            };

            if (client.RedirectUris != null)
            {
                ret.RedirectUris =
                    (from item in client.RedirectUris
                     select item.RedirectUri).ToArray();
            }
            else
            {
                ret.RedirectUris = new string[0];
            }
            
            return ret;
        }
 public OpenIdConnectClientViewModel(Models.OpenIdConnectClient client)
 {
     Container.Current.SatisfyImportsOnce(this);
     this.Client = client;
     this.MapRedirectUris();
 }