public void Properties_Map() { var model = new Client() { Properties = { { "foo1", "bar1" }, { "foo2", "bar2" }, } }; var mappedEntity = model.ToEntity(); mappedEntity.Properties.Count.Should().Be(2); var foo1 = mappedEntity.Properties.FirstOrDefault(x => x.Key == "foo1"); foo1.Should().NotBeNull(); foo1.Value.Should().Be("bar1"); var foo2 = mappedEntity.Properties.FirstOrDefault(x => x.Key == "foo2"); foo2.Should().NotBeNull(); foo2.Value.Should().Be("bar2"); var mappedModel = mappedEntity.ToModel(); mappedModel.Properties.Count.Should().Be(2); mappedModel.Properties.ContainsKey("foo1").Should().BeTrue(); mappedModel.Properties.ContainsKey("foo2").Should().BeTrue(); mappedModel.Properties["foo1"].Should().Be("bar1"); mappedModel.Properties["foo2"].Should().Be("bar2"); }
public void Can_Map() { var model = new Client(); var mappedEntity = model.ToEntity(); var mappedModel = mappedEntity.ToModel(); Assert.NotNull(mappedModel); Assert.NotNull(mappedEntity); }
public void missing_values_should_use_defaults() { var entity = new Duende.IdentityServer.EntityFramework.Entities.Client { ClientSecrets = new System.Collections.Generic.List <Duende.IdentityServer.EntityFramework.Entities.ClientSecret> { new Duende.IdentityServer.EntityFramework.Entities.ClientSecret { } } }; var def = new Client { ClientSecrets = { new Duende.IdentityServer.Models.Secret("foo") } }; var model = entity.ToModel(); model.ProtocolType.Should().Be(def.ProtocolType); model.ClientSecrets.First().Type.Should().Be(def.ClientSecrets.First().Type); }
private static void SeedClientGrantType(IAdminStore <Entity.ClientGrantType> clientGrantTypeStore, Duende.IdentityServer.Models.Client client) { foreach (var grantType in client.AllowedGrantTypes) { clientGrantTypeStore.CreateAsync(new Entity.ClientGrantType { ClientId = client.ClientId, GrantType = grantType, Id = Guid.NewGuid().ToString() }).GetAwaiter().GetResult(); } }
private static void SeedClientClaims(IAdminStore <Entity.ClientClaim> clientClaimStore, Duende.IdentityServer.Models.Client client) { foreach (var claim in client.Claims) { clientClaimStore.CreateAsync(new Entity.ClientClaim { ClientId = client.ClientId, Id = Guid.NewGuid().ToString(), Type = claim.Type, Value = claim.Value }).GetAwaiter().GetResult(); } }
private static void SeedClientSecrets(IAdminStore <Entity.ClientSecret> clientSecretStore, Duende.IdentityServer.Models.Client client) { foreach (var secret in client.ClientSecrets) { clientSecretStore.CreateAsync(new Entity.ClientSecret { ClientId = client.ClientId, Description = secret.Description, Expiration = secret.Expiration, Id = Guid.NewGuid().ToString(), Type = secret.Type, Value = secret.Value }).GetAwaiter().GetResult(); } }
private static void SeedClientRestrictions(IAdminStore <Entity.ClientIdpRestriction> clientIdpRestrictionStore, Duende.IdentityServer.Models.Client client) { foreach (var restriction in client.IdentityProviderRestrictions) { clientIdpRestrictionStore.CreateAsync(new Entity.ClientIdpRestriction { ClientId = client.ClientId, Id = Guid.NewGuid().ToString(), Provider = restriction }).GetAwaiter().GetResult(); } }
private static void SeedClientProperties(IAdminStore <Entity.ClientProperty> clientPropertyStore, Duende.IdentityServer.Models.Client client) { foreach (var property in client.Properties) { clientPropertyStore.CreateAsync(new Entity.ClientProperty { ClientId = client.ClientId, Id = Guid.NewGuid().ToString(), Key = property.Key, Value = property.Value }).GetAwaiter().GetResult(); } }
private static void SeedClientUris(IAdminStore <Entity.ClientUri> clientUriStore, Duende.IdentityServer.Models.Client client) { var uris = client.RedirectUris.Select(o => new Entity.ClientUri { Id = Guid.NewGuid().ToString(), ClientId = client.ClientId, Uri = o }).ToList(); foreach (var origin in client.AllowedCorsOrigins) { var cors = new Uri(origin); var uri = uris.FirstOrDefault(u => cors.CorsMatch(u.Uri)); var corsUri = new Uri(origin); var sanetized = $"{corsUri.Scheme.ToUpperInvariant()}://{corsUri.Host.ToUpperInvariant()}:{corsUri.Port}"; if (uri == null) { uris.Add(new Entity.ClientUri { Id = Guid.NewGuid().ToString(), ClientId = client.ClientId, Uri = origin, Kind = Entity.UriKinds.Cors, SanetizedCorsUri = sanetized }); continue; } uri.SanetizedCorsUri = sanetized; uri.Kind = Entity.UriKinds.Redirect | Entity.UriKinds.Cors; } foreach (var postLogout in client.PostLogoutRedirectUris) { var uri = uris.FirstOrDefault(u => u.Uri == postLogout); if (uri == null) { uris.Add(new Entity.ClientUri { Id = Guid.NewGuid().ToString(), ClientId = client.ClientId, Uri = postLogout, Kind = Entity.UriKinds.PostLogout }); continue; } uri.Kind |= Entity.UriKinds.Redirect; } foreach (var uri in uris) { clientUriStore.CreateAsync(uri).GetAwaiter().GetResult(); } }