From 20ae2c56330ed6958ad676eca47e50acf4855a5d Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Wed, 2 Jan 2019 17:16:13 +0300 Subject: [PATCH] IdentityServer Client improvements --- .../Volo/Abp/IdentityServer/Clients/Client.cs | 10 ++ .../IdentityServer/Clients/ClientSecret.cs | 5 + .../Volo/Abp/IdentityServer/Secret.cs | 1 + .../Clients/ClientRepository.cs | 98 +++++++++---------- 4 files changed, 65 insertions(+), 49 deletions(-) diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/Client.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/Client.cs index bfc9398802..cc2fae9900 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/Client.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/Client.cs @@ -163,11 +163,21 @@ namespace Volo.Abp.IdentityServer.Clients ClientSecrets.Add(new ClientSecret(Id, value, expiration, type, description)); } + public virtual void RemoveSecret([NotNull] string value, string type = IdentityServerConstants.SecretTypes.SharedSecret) + { + ClientSecrets.RemoveAll(s => s.Value == value && s.Type == type); + } + public virtual void RemoveAllSecrets() { ClientSecrets.Clear(); } + public virtual ClientSecret FindSecret([NotNull] string value, string type = IdentityServerConstants.SecretTypes.SharedSecret) + { + return ClientSecrets.FirstOrDefault(s => s.Type == type && s.Value == value); + } + public virtual void AddScope([NotNull] string scope) { AllowedScopes.Add(new ClientScope(Id, scope)); diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientSecret.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientSecret.cs index c46f4a2d34..01ed5d6f24 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientSecret.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientSecret.cs @@ -28,6 +28,11 @@ namespace Volo.Abp.IdentityServer.Clients ClientId = clientId; } + public virtual bool Equals(Guid clientId, [NotNull] string value, string type = IdentityServerConstants.SecretTypes.SharedSecret) + { + return ClientId == clientId && Value == value && Type == type; + } + public override object[] GetKeys() { return new object[] { ClientId, Type, Value }; diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Secret.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Secret.cs index faef3a12ed..f09b4dfb49 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Secret.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Secret.cs @@ -1,5 +1,6 @@ using System; using IdentityServer4; +using IdentityServer4.Models; using JetBrains.Annotations; using Volo.Abp.Domain.Entities; diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Clients/ClientRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Clients/ClientRepository.cs index 202d1cd6aa..aee58475fe 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Clients/ClientRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Clients/ClientRepository.cs @@ -42,74 +42,74 @@ namespace Volo.Abp.IdentityServer.Clients return await DbSet.CountAsync(); } - public override async Task UpdateAsync(Client entity, bool autoSave = false, CancellationToken cancellationToken = default) - { + //public override async Task UpdateAsync(Client entity, bool autoSave = false, CancellationToken cancellationToken = default) + //{ - var secrets = DbContext.Set().Where(s => s.ClientId == entity.Id); + // var secrets = DbContext.Set().Where(s => s.ClientId == entity.Id); - foreach (var secret in secrets) - { - DbContext.Set().Remove(secret); - } + // foreach (var secret in secrets) + // { + // DbContext.Set().Remove(secret); + // } - var claims = DbContext.Set().Where(s => s.ClientId == entity.Id); + // var claims = DbContext.Set().Where(s => s.ClientId == entity.Id); - foreach (var claim in claims) - { - DbContext.Set().Remove(claim); - } + // foreach (var claim in claims) + // { + // DbContext.Set().Remove(claim); + // } - var grantTypes = DbContext.Set().Where(s => s.ClientId == entity.Id); + // var grantTypes = DbContext.Set().Where(s => s.ClientId == entity.Id); - foreach (var grantType in grantTypes) - { - DbContext.Set().Remove(grantType); - } + // foreach (var grantType in grantTypes) + // { + // DbContext.Set().Remove(grantType); + // } - var restrictions = DbContext.Set().Where(s => s.ClientId == entity.Id); + // var restrictions = DbContext.Set().Where(s => s.ClientId == entity.Id); - foreach (var restriction in restrictions) - { - DbContext.Set().Remove(restriction); - } + // foreach (var restriction in restrictions) + // { + // DbContext.Set().Remove(restriction); + // } - var properties = DbContext.Set().Where(s => s.ClientId == entity.Id); + // var properties = DbContext.Set().Where(s => s.ClientId == entity.Id); - foreach (var clientProperty in properties) - { - DbContext.Set().Remove(clientProperty); - } + // foreach (var clientProperty in properties) + // { + // DbContext.Set().Remove(clientProperty); + // } - var scopes = DbContext.Set().Where(s => s.ClientId == entity.Id); + // var scopes = DbContext.Set().Where(s => s.ClientId == entity.Id); - foreach (var scope in scopes) - { - DbContext.Set().Remove(scope); - } + // foreach (var scope in scopes) + // { + // DbContext.Set().Remove(scope); + // } - var corsOrigins = DbContext.Set().Where(s => s.ClientId == entity.Id); + // var corsOrigins = DbContext.Set().Where(s => s.ClientId == entity.Id); - foreach (var corsOrigin in corsOrigins) - { - DbContext.Set().Remove(corsOrigin); - } + // foreach (var corsOrigin in corsOrigins) + // { + // DbContext.Set().Remove(corsOrigin); + // } - var redirectUris = DbContext.Set().Where(s => s.ClientId == entity.Id); + // var redirectUris = DbContext.Set().Where(s => s.ClientId == entity.Id); - foreach (var redirectUri in redirectUris) - { - DbContext.Set().Remove(redirectUri); - } + // foreach (var redirectUri in redirectUris) + // { + // DbContext.Set().Remove(redirectUri); + // } - var postLogoutRedirectUris = DbContext.Set().Where(s => s.ClientId == entity.Id); + // var postLogoutRedirectUris = DbContext.Set().Where(s => s.ClientId == entity.Id); - foreach (var postLogoutRedirectUri in postLogoutRedirectUris) - { - DbContext.Set().Remove(postLogoutRedirectUri); - } + // foreach (var postLogoutRedirectUri in postLogoutRedirectUris) + // { + // DbContext.Set().Remove(postLogoutRedirectUri); + // } - return await base.UpdateAsync(entity, autoSave, cancellationToken); - } + // return await base.UpdateAsync(entity, autoSave, cancellationToken); + //} public override IQueryable WithDetails() {