示例#1
0
        public static OpenIdConnectClient ToDomainModel(this OpenIdConnectClientEntity client)
        {
            var ret = new 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(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 Create(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();
            }
        }
示例#4
0
        public static void UpdateEntity(this OpenIdConnectClient client, 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 = 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
                    });
                }
            }
        }
示例#5
0
        public static void UpdateEntity(this OpenIdConnectClient client, 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 = 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});
                }
            }
        }