protected override ICollection <Entity.ClientClaim> GetCollection(Entity.Client client)
        {
            if (client.ClientClaims == null)
            {
                client.ClientClaims = new List <Entity.ClientClaim>();
            }

            return(client.ClientClaims);
        }
Beispiel #2
0
        protected override ICollection <Entity.ClientProperty> GetCollection(Entity.Client client)
        {
            if (client.Properties == null)
            {
                client.Properties = new List <Entity.ClientProperty>();
            }

            return(client.Properties);
        }
Beispiel #3
0
        protected override ICollection <Entity.ClientScope> GetCollection(Entity.Client client)
        {
            if (client.AllowedScopes == null)
            {
                client.AllowedScopes = new List <Entity.ClientScope>();
            }

            return(client.AllowedScopes);
        }
Beispiel #4
0
        protected override ICollection <Entity.ClientIdpRestriction> GetCollection(Entity.Client client)
        {
            if (client.IdentityProviderRestrictions == null)
            {
                client.IdentityProviderRestrictions = new List <Entity.ClientIdpRestriction>();
            }

            return(client.IdentityProviderRestrictions);
        }
Beispiel #5
0
        protected override ICollection <Entity.ClientUri> GetCollection(Entity.Client client)
        {
            if (client.RedirectUris == null)
            {
                client.RedirectUris = new List <Entity.ClientUri>();
            }

            return(client.RedirectUris);
        }
Beispiel #6
0
        public async Task DeleteAsync_should_remove_entity_id_from_parent()
        {
            using var store = new RavenDbTestDriverWrapper().GetDocumentStore();

            var entity = new TEntity
            {
                Id       = Guid.NewGuid().ToString(),
                ClientId = "test"
            };
            var api = new Entity.Client
            {
                Id = "test",
            };
            var collection = GetCollection(api);

            collection.Add(new TEntity
            {
                Id = $"{typeof(TEntity).Name.ToLowerInvariant()}/{entity.Id}"
            });

            using var s1 = store.OpenAsyncSession();
            await s1.StoreAsync(api, $"{nameof(Entity.Client).ToLowerInvariant()}/{api.Id}");

            await s1.StoreAsync(entity, $"{typeof(TEntity).Name.ToLowerInvariant()}/{entity.Id}");

            await s1.SaveChangesAsync();

            var loggerMock = new Mock <ILogger <AdminStore <TEntity> > >();

            using var session = store.OpenAsyncSession();

            var sut = CreateSut(session, loggerMock.Object);


            await sut.DeleteAsync(entity.Id);

            using var s2 = store.OpenAsyncSession();
            var updated = await s2.LoadAsync <Entity.Client>($"{nameof(Entity.Client).ToLowerInvariant()}/test");

            var updatedCollection = GetCollection(updated);

            Assert.DoesNotContain(updatedCollection, i => i.Id == $"{typeof(TEntity).Name.ToLowerInvariant()}/{entity.Id}");
        }
Beispiel #7
0
 public ClientUriValidator(Entity.Client _, IStringLocalizer localizer)
 {
     RuleFor(m => m.Uri).MaximumLength(2000).WithMessage(localizer["An url cannot exceed 2000 char."]);
     RuleFor(m => m.Uri).Uri().WithMessage((c, v) => $"The url '{v}' is not valid.");
 }
Beispiel #8
0
        public static Client ToClient(this Entity.Client client)
        {
            if (client == null)
            {
                return(null);
            }
            var cultureId = CultureInfo.CurrentCulture.Name;
            var resources = client.Resources;
            var policyUri = resources.FirstOrDefault(r => r.ResourceKind == Entity.EntityResourceKind.PolicyUri &&
                                                     r.CultureId == cultureId)?.Value ?? client.PolicyUri;

            if (policyUri != null)
            {
                client.Properties.Add(new Entity.ClientProperty
                {
                    Key   = "PolicyUrl",
                    Value = policyUri
                });
            }
            var tosUri = resources.FirstOrDefault(r => r.ResourceKind == Entity.EntityResourceKind.TosUri &&
                                                  r.CultureId == cultureId)?.Value ?? client.TosUri;

            if (policyUri != null)
            {
                client.Properties.Add(new Entity.ClientProperty
                {
                    Key   = "TosUrl",
                    Value = tosUri
                });
            }
            return(new Client
            {
                AbsoluteRefreshTokenLifetime = client.AbsoluteRefreshTokenLifetime,
                AccessTokenLifetime = client.AccessTokenLifetime,
                AccessTokenType = (AccessTokenType)client.AccessTokenType,
                AllowAccessTokensViaBrowser = client.AllowAccessTokensViaBrowser,
                AllowedCorsOrigins = client.RedirectUris
                                     .Where(u => (u.Kind & Entity.UriKinds.Cors) == Entity.UriKinds.Cors)
                                     .Select(u => new Uri(u.Uri))
                                     .Select(u => $"{u.Scheme}://{u.Host}{u.UriPortString()}")
                                     .ToList(),
                AllowedGrantTypes = client.AllowedGrantTypes.Select(g => g.GrantType).ToList(),
                AllowedScopes = client.AllowedScopes.Select(s => s.Scope).ToList(),
                AllowOfflineAccess = client.AllowOfflineAccess,
                AllowPlainTextPkce = client.AllowPlainTextPkce,
                AllowRememberConsent = client.AllowRememberConsent,
                AlwaysIncludeUserClaimsInIdToken = client.AlwaysIncludeUserClaimsInIdToken,
                AlwaysSendClientClaims = client.AlwaysSendClientClaims,
                AuthorizationCodeLifetime = client.AuthorizationCodeLifetime,
                BackChannelLogoutSessionRequired = client.BackChannelLogoutSessionRequired,
                BackChannelLogoutUri = client.BackChannelLogoutUri,
                Claims = client.ClientClaims.Select(c => new ClientClaim(c.Type, c.Value)).ToList(),
                ClientClaimsPrefix = client.ClientClaimsPrefix,
                ClientId = client.Id,
                ClientName = resources.FirstOrDefault(r => r.ResourceKind == Entity.EntityResourceKind.DisplayName &&
                                                      r.CultureId == cultureId)?.Value ?? client.ClientName,
                ClientSecrets = client.ClientSecrets.Select(s => new Secret
                {
                    Value = s.Value,
                    Expiration = s.Expiration,
                    Description = s.Description,
                    Type = s.Type
                }).ToList(),
                ClientUri = resources.FirstOrDefault(r => r.ResourceKind == Entity.EntityResourceKind.ClientUri &&
                                                     r.CultureId == cultureId)?.Value ?? client.ClientUri,
                ConsentLifetime = client.ConsentLifetime,
                Description = resources.FirstOrDefault(r => r.ResourceKind == Entity.EntityResourceKind.Description &&
                                                       r.CultureId == cultureId)?.Value ?? client.Description,
                DeviceCodeLifetime = client.DeviceCodeLifetime,
                Enabled = client.Enabled,
                EnableLocalLogin = client.EnableLocalLogin,
                FrontChannelLogoutSessionRequired = client.FrontChannelLogoutSessionRequired,
                FrontChannelLogoutUri = client.FrontChannelLogoutUri,
                IdentityProviderRestrictions = client.IdentityProviderRestrictions.Select(r => r.Provider).ToList(),
                IdentityTokenLifetime = client.IdentityTokenLifetime,
                IncludeJwtId = client.IncludeJwtId,
                LogoUri = resources.FirstOrDefault(r => r.ResourceKind == Entity.EntityResourceKind.LogoUri &&
                                                   r.CultureId == cultureId)?.Value ?? client.LogoUri,
                PairWiseSubjectSalt = client.PairWiseSubjectSalt,
                PostLogoutRedirectUris = client.RedirectUris
                                         .Where(u => (u.Kind & Entity.UriKinds.PostLogout) == Entity.UriKinds.PostLogout)
                                         .Select(u => u.Uri).ToList(),
                Properties = client.Properties.ToDictionary(p => p.Key, p => p.Value),
                ProtocolType = client.ProtocolType,
                RefreshTokenExpiration = (TokenExpiration)client.RefreshTokenExpiration,
                RedirectUris = client.RedirectUris
                               .Where(u => (u.Kind & Entity.UriKinds.Redirect) == Entity.UriKinds.Redirect)
                               .Select(u => u.Uri).ToList(),
                RefreshTokenUsage = (TokenUsage)client.RefreshTokenUsage,
                RequireClientSecret = client.RequireClientSecret,
                RequireConsent = client.RequireConsent,
                RequirePkce = client.RequirePkce,
                SlidingRefreshTokenLifetime = client.SlidingRefreshTokenLifetime,
                UpdateAccessTokenClaimsOnRefresh = client.UpdateAccessTokenClaimsOnRefresh,
                UserCodeType = client.UserCodeType,
                UserSsoLifetime = client.UserSsoLifetime
            });
        }
Beispiel #9
0
 protected abstract ICollection <TEntity> GetCollection(Entity.Client client);
Beispiel #10
0
        protected override ICollection <Entity.ClientLocalizedResource> GetCollection(Entity.Client client)
        {
            if (client.Resources == null)
            {
                client.Resources = new List <Entity.ClientLocalizedResource>();
            }

            return(client.Resources);
        }