Ejemplo n.º 1
0
        public void duplicates_properties_in_db_map()
        {
            var entity = new IdentityServer4.EntityFramework.Entities.Client
            {
                Properties = new System.Collections.Generic.List <Entities.ClientProperty>()
                {
                    new Entities.ClientProperty {
                        Key = "foo1", Value = "bar1"
                    },
                    new Entities.ClientProperty {
                        Key = "foo1", Value = "bar2"
                    },
                }
            };

            Action modelAction = () => entity.ToModel();

            modelAction.ShouldThrow <Exception>();
        }
        public void missing_values_should_use_defaults()
        {
            var entity = new IdentityServer4.EntityFramework.Entities.Client
            {
                ClientSecrets = new System.Collections.Generic.List <Entities.ClientSecret>
                {
                    new Entities.ClientSecret
                    {
                    }
                }
            };

            var def = new Client
            {
                ClientSecrets = { new Models.Secret("foo") }
            };

            var model = entity.ToModel();

            model.ProtocolType.Should().Be(def.ProtocolType);
            model.ClientSecrets.First().Type.Should().Be(def.ClientSecrets.First().Type);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get seed for clients
        /// </summary>
        /// <param name="clients"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public static IEnumerable <identityModels.Client> GetSeedClients(this IEnumerable <Client> clients, ConfigurationDbContext context)
        {
            //TODO: Replace with ToEntity() from AutoMapper extensions, the current version of AutoMapper and Identity.Server4 crash
            var index            = 1;
            var enumerateClients = clients.ToList();

            foreach (var client in enumerateClients)
            {
                var retClient = new identityModels.Client
                {
                    Id      = index++,
                    Enabled = client.Enabled,
                    Created = DateTime.Now,
                    AbsoluteRefreshTokenLifetime = client.AbsoluteRefreshTokenLifetime,
                    AccessTokenLifetime          = client.AccessTokenLifetime,
                    AccessTokenType             = client.AccessTokenLifetime,
                    AllowAccessTokensViaBrowser = client.AllowAccessTokensViaBrowser,
                    AllowOfflineAccess          = client.AllowOfflineAccess,
                    AllowPlainTextPkce          = client.AllowPlainTextPkce,
                    AllowRememberConsent        = client.AllowRememberConsent,
                    AllowedCorsOrigins          = client.AllowedCorsOrigins.Select(x => new identityModels.ClientCorsOrigin
                    {
                        Id       = GenerateIndex($"{index}{client.AllowedCorsOrigins.IndexOf(x)}"),
                        ClientId = index,
                        Origin   = x
                    }).ToList(),
                    ClientId          = client.ClientId,
                    AllowedGrantTypes = client.AllowedGrantTypes.Select(x => new identityModels.ClientGrantType
                    {
                        Id        = GenerateIndex($"{index}{client.AllowedGrantTypes.IndexOf(x)}"),
                        ClientId  = index,
                        GrantType = x
                    }).ToList(),
                    AllowedScopes = client.AllowedScopes.Select(x => new identityModels.ClientScope
                    {
                        Id       = GenerateIndex($"{index}{client.AllowedScopes.IndexOf(x)}"),
                        ClientId = index,
                        Scope    = x
                    }).ToList(),
                    AlwaysIncludeUserClaimsInIdToken = client.AlwaysIncludeUserClaimsInIdToken,
                    AlwaysSendClientClaims           = client.AlwaysSendClientClaims,
                    AuthorizationCodeLifetime        = client.AuthorizationCodeLifetime,
                    BackChannelLogoutSessionRequired = client.BackChannelLogoutSessionRequired,
                    BackChannelLogoutUri             = client.BackChannelLogoutUri,
                    Claims = client.Claims.Select(x => new identityModels.ClientClaim()
                    {
                        Id       = GenerateIndex($"{index}{client.Claims.IndexOf(x)}"),
                        ClientId = index,
                        Value    = x.Value,
                        Type     = x.Type
                    }).ToList(),
                    ClientClaimsPrefix = client.ClientClaimsPrefix,
                    ClientName         = client.ClientName,
                    ClientSecrets      = client.ClientSecrets.Select(x => new identityModels.ClientSecret()
                    {
                        Id          = GenerateIndex($"{index}{client.ClientSecrets.IndexOf(x)}"),
                        ClientId    = index,
                        Value       = x.Value,
                        Type        = x.Type,
                        Created     = DateTime.Now,
                        Description = x.Description,
                        Expiration  = x.Expiration
                    }).ToList(),
                    Description        = client.Description,
                    ClientUri          = client.ClientUri,
                    ConsentLifetime    = client.ConsentLifetime,
                    DeviceCodeLifetime = client.DeviceCodeLifetime,
                    EnableLocalLogin   = client.EnableLocalLogin,
                    FrontChannelLogoutSessionRequired = client.FrontChannelLogoutSessionRequired,
                    FrontChannelLogoutUri             = client.FrontChannelLogoutUri,
                    IdentityProviderRestrictions      = client.IdentityProviderRestrictions.Select(x => new identityModels.ClientIdPRestriction
                    {
                        Id       = GenerateIndex($"{index}{client.IdentityProviderRestrictions.IndexOf(x)}"),
                        ClientId = index,
                        Provider = x
                    }).ToList(),
                    IdentityTokenLifetime = client.IdentityTokenLifetime,
                    IncludeJwtId          = client.IncludeJwtId,
                    LastAccessed          = DateTime.Now,
                    LogoUri                = client.LogoUri,
                    NonEditable            = false,
                    PairWiseSubjectSalt    = client.PairWiseSubjectSalt,
                    PostLogoutRedirectUris = client.PostLogoutRedirectUris.Select(x => new identityModels.ClientPostLogoutRedirectUri
                    {
                        Id       = GenerateIndex($"{index}{client.PostLogoutRedirectUris.IndexOf(x)}"),
                        ClientId = index,
                        PostLogoutRedirectUri = x
                    }).ToList(),
                    ProtocolType = client.ProtocolType,
                    RedirectUris = client.RedirectUris.Select(x => new identityModels.ClientRedirectUri
                    {
                        Id          = GenerateIndex($"{index}{client.RedirectUris.IndexOf(x)}"),
                        ClientId    = index,
                        RedirectUri = x
                    }).ToList(),
                    RefreshTokenUsage                = (int)client.RefreshTokenUsage,
                    RefreshTokenExpiration           = (int)client.RefreshTokenExpiration,
                    RequireClientSecret              = client.RequireClientSecret,
                    RequireConsent                   = client.RequireConsent,
                    RequirePkce                      = client.RequirePkce,
                    SlidingRefreshTokenLifetime      = client.SlidingRefreshTokenLifetime,
                    UpdateAccessTokenClaimsOnRefresh = client.UpdateAccessTokenClaimsOnRefresh,
                    Updated         = DateTime.Now,
                    UserCodeType    = client.UserCodeType,
                    UserSsoLifetime = client.UserSsoLifetime
                };

                yield return(retClient);
            }
        }