From 1a3f20b59be13c20a36a781437bb5e2e261e608a Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 8 Jan 2019 10:30:58 +0300 Subject: [PATCH 1/5] identity server clients refactor --- .../Volo/Abp/IdentityServer/Clients/Client.cs | 105 +++++++++++++++--- .../Abp/IdentityServer/Clients/ClientClaim.cs | 17 ++- .../Clients/ClientCorsOrigin.cs | 7 +- .../IdentityServer/Clients/ClientGrantType.cs | 5 + .../Clients/ClientIdPRestriction.cs | 5 + .../Clients/ClientPostLogoutRedirectUri.cs | 5 + .../IdentityServer/Clients/ClientProperty.cs | 5 + .../Clients/ClientRedirectUri.cs | 5 + .../Abp/IdentityServer/Clients/ClientScope.cs | 6 + ...yServerDbContextModelCreatingExtensions.cs | 2 + 10 files changed, 140 insertions(+), 22 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 8c4846102b..f45926fb9a 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 @@ -144,18 +144,19 @@ namespace Volo.Abp.IdentityServer.Clients AllowedGrantTypes.Add(new ClientGrantType(Id, grantType)); } - public virtual void AddGrantTypes(IEnumerable grantTypes) + public virtual void RemoveAllAllowedGrantTypes() { - AllowedGrantTypes.AddRange( - grantTypes.Select( - grantType => new ClientGrantType(Id, grantType) - ) - ); + AllowedGrantTypes.Clear(); } - public virtual void RemoveAllAllowedGrantTypes() + public virtual void RemoveGrantType(string grantType) { - AllowedGrantTypes.Clear(); + AllowedGrantTypes.RemoveAll(r => r.GrantType == grantType); + } + + public virtual ClientGrantType FindGrantType(string grantType) + { + return AllowedGrantTypes.FirstOrDefault(r => r.GrantType == grantType); } public virtual void AddSecret([NotNull] string value, DateTime? expiration = null, string type = IdentityServerConstants.SecretTypes.SharedSecret, string description = null) @@ -183,6 +184,16 @@ namespace Volo.Abp.IdentityServer.Clients AllowedScopes.Clear(); } + public virtual void RemoveScope(string scope) + { + AllowedScopes.RemoveAll(r => r.Scope == scope); + } + + public virtual ClientScope FindScope(string scope) + { + return AllowedScopes.FirstOrDefault(r => r.Scope == scope); + } + public virtual void AddCorsOrigin([NotNull] string origin) { AllowedCorsOrigins.Add(new ClientCorsOrigin(Id, origin)); @@ -198,29 +209,49 @@ namespace Volo.Abp.IdentityServer.Clients PostLogoutRedirectUris.Add(new ClientPostLogoutRedirectUri(Id, postLogoutRedirectUri)); } - public virtual void RemoveAllCorsOrigin() + public virtual void RemoveAllCorsOrigins() { AllowedCorsOrigins.Clear(); } - public virtual void RemoveAllRedirectUri() + public virtual void RemoveCorsOrigin(string uri) + { + AllowedCorsOrigins.RemoveAll(c => c.Origin == uri); + } + + public virtual void RemoveAllRedirectUris() { RedirectUris.Clear(); } - public virtual void RemoveAllPostLogoutRedirectUri() + public virtual void RemoveRedirectUri(string uri) + { + RedirectUris.RemoveAll(r => r.RedirectUri == uri); + } + + public virtual void RemoveAllPostLogoutRedirectUris() { PostLogoutRedirectUris.Clear(); } - public virtual void AddIdentityProviderRestriction([NotNull] string provider) + public virtual void RemovePostLogoutRedirectUri(string uri) { - IdentityProviderRestrictions.Add(new ClientIdPRestriction(Id, provider)); + PostLogoutRedirectUris.RemoveAll(p => p.PostLogoutRedirectUri == uri); } - public virtual void RemoveAllIdentityProviderRestriction() + public virtual ClientCorsOrigin FindCorsOrigin(string uri) { - IdentityProviderRestrictions.Clear(); + return AllowedCorsOrigins.FirstOrDefault(c => c.Origin == uri); + } + + public virtual ClientRedirectUri FindRedirectUri(string uri) + { + return RedirectUris.FirstOrDefault(r => r.RedirectUri == uri); + } + + public virtual ClientPostLogoutRedirectUri FindPostLogoutRedirectUri(string uri) + { + return PostLogoutRedirectUris.FirstOrDefault(p => p.PostLogoutRedirectUri == uri); } public virtual void AddProperty([NotNull] string key, [NotNull] string value) @@ -233,14 +264,54 @@ namespace Volo.Abp.IdentityServer.Clients Properties.Clear(); } - public virtual void AddClaim(IGuidGenerator guidGenerator, [NotNull] string type, string value) + public virtual void RemoveProperty(string key, string value) { - Claims.Add(new ClientClaim(guidGenerator.Create(), Id, type, value)); + Properties.RemoveAll(c => c.Value == value && c.Key == key); + } + + public virtual ClientProperty FindProperty(string key, string value) + { + return Properties.FirstOrDefault(c => c.Key == key && c.Value == value); + } + + public virtual void AddClaim([NotNull] string value, string type) + { + Claims.Add(new ClientClaim(Id, type, value)); } public virtual void RemoveAllClaims() { Claims.Clear(); } + + public virtual void RemoveClaim(string value, string type) + { + Claims.RemoveAll(c => c.Value == value && c.Type == type); + } + + public virtual ClientClaim FindClaim(string value, string type) + { + return Claims.FirstOrDefault(c => c.Type == type && c.Value == value); + } + + public virtual void AddIdentityProviderRestriction([NotNull] string provider) + { + IdentityProviderRestrictions.Add(new ClientIdPRestriction(Id, provider)); + } + + public virtual void RemoveAllIdentityProviderRestrictions() + { + IdentityProviderRestrictions.Clear(); + } + + public virtual void RemoveIdentityProviderRestriction(string provider) + { + IdentityProviderRestrictions.RemoveAll(r => r.Provider == provider); + } + + public virtual ClientIdPRestriction FindIdentityProviderRestriction(string provider) + { + return IdentityProviderRestrictions.FirstOrDefault(r => r.Provider == provider); + } } } \ No newline at end of file diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientClaim.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientClaim.cs index 29b44a40f7..f0b35d772a 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientClaim.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientClaim.cs @@ -4,7 +4,7 @@ using Volo.Abp.Domain.Entities; namespace Volo.Abp.IdentityServer.Clients { - public class ClientClaim : Entity + public class ClientClaim : Entity { public virtual Guid ClientId { get; set; } @@ -14,17 +14,26 @@ namespace Volo.Abp.IdentityServer.Clients protected ClientClaim() { - + + } + + public virtual bool Equals(Guid clientId, string value, string type) + { + return ClientId == clientId && Type == type && Value == value; } - protected internal ClientClaim(Guid id, Guid clientId, [NotNull] string type, string value) + protected internal ClientClaim(Guid clientId, [NotNull] string type, string value) { Check.NotNull(type, nameof(type)); - Id = id; ClientId = clientId; Type = type; Value = value; } + + public override object[] GetKeys() + { + return new object[] { ClientId, Type, Value }; + } } } \ No newline at end of file diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientCorsOrigin.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientCorsOrigin.cs index c8177baee8..73f4b47637 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientCorsOrigin.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientCorsOrigin.cs @@ -12,7 +12,12 @@ namespace Volo.Abp.IdentityServer.Clients protected ClientCorsOrigin() { - + + } + + public virtual bool Equals(Guid clientId, [NotNull] string uri) + { + return ClientId == clientId && Origin == uri; } protected internal ClientCorsOrigin(Guid clientId, [NotNull] string origin) diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientGrantType.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientGrantType.cs index ccbf0b666e..696ae1cd46 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientGrantType.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientGrantType.cs @@ -15,6 +15,11 @@ namespace Volo.Abp.IdentityServer.Clients } + public virtual bool Equals(Guid clientId, [NotNull] string grantType) + { + return ClientId == clientId && GrantType == grantType; + } + protected internal ClientGrantType(Guid clientId, [NotNull] string grantType) { Check.NotNull(grantType, nameof(grantType)); diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientIdPRestriction.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientIdPRestriction.cs index 00f1aa1020..aff16986c2 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientIdPRestriction.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientIdPRestriction.cs @@ -15,6 +15,11 @@ namespace Volo.Abp.IdentityServer.Clients } + public virtual bool Equals(Guid clientId, [NotNull] string provider) + { + return ClientId == clientId && Provider == provider; + } + protected internal ClientIdPRestriction(Guid clientId, [NotNull] string provider) { Check.NotNull(provider, nameof(provider)); diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUri.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUri.cs index 9042d54522..0e0ca17ae8 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUri.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUri.cs @@ -15,6 +15,11 @@ namespace Volo.Abp.IdentityServer.Clients } + public virtual bool Equals(Guid clientId, [NotNull] string uri) + { + return ClientId == clientId && PostLogoutRedirectUri == uri; + } + protected internal ClientPostLogoutRedirectUri(Guid clientId, [NotNull] string postLogoutRedirectUri) { Check.NotNull(postLogoutRedirectUri, nameof(postLogoutRedirectUri)); diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientProperty.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientProperty.cs index 31d131e762..daddd94e83 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientProperty.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientProperty.cs @@ -17,6 +17,11 @@ namespace Volo.Abp.IdentityServer.Clients } + public virtual bool Equals(Guid clientId, [NotNull] string key, string value) + { + return ClientId == clientId && Key == key && Value == value; + } + protected internal ClientProperty(Guid clientId, [NotNull] string key, [NotNull] string value) { Check.NotNull(key, nameof(key)); diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientRedirectUri.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientRedirectUri.cs index ff8a3edc05..89d461b58b 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientRedirectUri.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientRedirectUri.cs @@ -15,6 +15,11 @@ namespace Volo.Abp.IdentityServer.Clients } + public virtual bool Equals(Guid clientId, [NotNull] string uri) + { + return ClientId == clientId && RedirectUri == uri; + } + protected internal ClientRedirectUri(Guid clientId, [NotNull] string redirectUri) { Check.NotNull(redirectUri, nameof(redirectUri)); diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientScope.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientScope.cs index eb72ddf7cb..f94de116bb 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientScope.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientScope.cs @@ -1,4 +1,5 @@ using System; +using JetBrains.Annotations; using Volo.Abp.Domain.Entities; namespace Volo.Abp.IdentityServer.Clients @@ -14,6 +15,11 @@ namespace Volo.Abp.IdentityServer.Clients } + public virtual bool Equals(Guid clientId, [NotNull] string scope) + { + return ClientId == clientId && Scope == scope; + } + protected internal ClientScope(Guid clientId, string scope) { ClientId = clientId; diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContextModelCreatingExtensions.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContextModelCreatingExtensions.cs index efda009d68..3c38f2e2c7 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContextModelCreatingExtensions.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContextModelCreatingExtensions.cs @@ -103,6 +103,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore { claim.ToTable(tablePrefix + "ClientClaims", schema); + claim.HasKey(x => new { x.ClientId, x.Type, x.Value }); + claim.Property(x => x.Type).HasMaxLength(ClientClaimConsts.TypeMaxLength).IsRequired(); claim.Property(x => x.Value).HasMaxLength(ClientClaimConsts.ValueMaxLength).IsRequired(); }); From c132d469683cd9f8a3735a4d4dfa2541d57d68bb Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 8 Jan 2019 10:42:24 +0300 Subject: [PATCH 2/5] identity server identityresource refactor --- .../IdentityServer/IdentityResources/IdentityClaim.cs | 7 ++++++- .../IdentityResources/IdentityResource.cs | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityClaim.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityClaim.cs index 39453421ef..8b4a22b584 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityClaim.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityClaim.cs @@ -9,7 +9,12 @@ namespace Volo.Abp.IdentityServer.IdentityResources protected IdentityClaim() { - + + } + + public virtual bool Equals(Guid identityResourceId, [NotNull] string type) + { + return IdentityResourceId == identityResourceId && Type == type; } protected internal IdentityClaim(Guid identityResourceId, [NotNull] string type) diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResource.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResource.cs index 37b259fe61..9ecaa42741 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResource.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResource.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using JetBrains.Annotations; using Volo.Abp.Domain.Entities; @@ -61,5 +62,15 @@ namespace Volo.Abp.IdentityServer.IdentityResources { UserClaims.Clear(); } + + public virtual void RemoveUserClaim(string type) + { + UserClaims.RemoveAll(c => c.Type == type); + } + + public virtual IdentityClaim FindUserClaim(string type) + { + return UserClaims.FirstOrDefault(c => c.Type == type); + } } } From 1e643381c32fff35ab096f7bf767637e3a1f6571 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 8 Jan 2019 11:45:39 +0300 Subject: [PATCH 3/5] identity server apiresource refactor --- .../ApiResources/ApiResource.cs | 40 +++++++++++++++++-- .../ApiResources/ApiResourceClaim.cs | 7 +++- .../IdentityServer/ApiResources/ApiScope.cs | 18 ++++++++- .../ApiResources/ApiScopeClaim.cs | 5 +++ .../IdentityServer/ApiResources/ApiSecret.cs | 7 +++- 5 files changed, 70 insertions(+), 7 deletions(-) diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResource.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResource.cs index fef31bdec5..c6c74ac24f 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResource.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResource.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using IdentityServer4; using JetBrains.Annotations; using Volo.Abp.Domain.Entities; @@ -57,16 +58,27 @@ namespace Volo.Abp.IdentityServer.ApiResources Secrets.Add(new ApiSecret(Id, value, expiration, type, description)); } - public virtual void AddScope( + public virtual void RemoveSecret([NotNull] string value, string type = IdentityServerConstants.SecretTypes.SharedSecret) + { + Secrets.RemoveAll(s => s.Value == value && s.Type == type); + } + + public virtual ApiSecret FindSecret([NotNull] string value, string type = IdentityServerConstants.SecretTypes.SharedSecret) + { + return Secrets.FirstOrDefault(s => s.Type == type && s.Value == value); + } + + public virtual ApiScope AddScope( [NotNull] string name, string displayName = null, string description = null, bool required = false, bool emphasize = false, - bool showInDiscoveryDocument = true, - ApiScopeClaim[] userClaims = null) + bool showInDiscoveryDocument = true) { - Scopes.Add(new ApiScope(Id, name, displayName, description, required, emphasize, showInDiscoveryDocument)); + var scope = new ApiScope(Id, name, displayName, description, required, emphasize, showInDiscoveryDocument); + Scopes.Add(scope); + return scope; } public virtual void AddUserClaim([NotNull] string type) @@ -79,6 +91,16 @@ namespace Volo.Abp.IdentityServer.ApiResources UserClaims.Clear(); } + public virtual void RemoveClaim(string type) + { + UserClaims.RemoveAll(c => c.Type == type); + } + + public virtual ApiResourceClaim FindClaim(string type) + { + return UserClaims.FirstOrDefault(c => c.Type == type); + } + public virtual void RemoveAllSecrets() { Secrets.Clear(); @@ -92,5 +114,15 @@ namespace Volo.Abp.IdentityServer.ApiResources } Scopes.Clear(); } + + public virtual void RemoveScope(string name) + { + Scopes.RemoveAll(r => r.Name == name); + } + + public virtual ApiScope FindScope(string name) + { + return Scopes.FirstOrDefault(r => r.Name == name); + } } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceClaim.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceClaim.cs index 89fec1c017..e71d694656 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceClaim.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceClaim.cs @@ -9,7 +9,12 @@ namespace Volo.Abp.IdentityServer.ApiResources protected ApiResourceClaim() { - + + } + + public virtual bool Equals(Guid apiResourceId, [NotNull] string type) + { + return ApiResourceId == apiResourceId && Type == type; } protected internal ApiResourceClaim(Guid apiResourceId, [NotNull] string type) diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScope.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScope.cs index f96debb31a..e81dd849ec 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScope.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScope.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using JetBrains.Annotations; using Volo.Abp.Domain.Entities; @@ -26,7 +27,12 @@ namespace Volo.Abp.IdentityServer.ApiResources protected ApiScope() { - + + } + + public virtual bool Equals(Guid apiResourceId, [NotNull] string name) + { + return ApiResourceId == apiResourceId && Name == name; } protected internal ApiScope( @@ -61,6 +67,16 @@ namespace Volo.Abp.IdentityServer.ApiResources UserClaims.Clear(); } + public virtual void RemoveClaim(string name, string type) + { + UserClaims.RemoveAll(r => r.Name == name && r.Type == type); + } + + public virtual ApiScopeClaim FindClaim(string name, string type) + { + return UserClaims.FirstOrDefault(r => r.Name == name && r.Type == type); + } + public override object[] GetKeys() { return new object[] { ApiResourceId, Name }; diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScopeClaim.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScopeClaim.cs index 5c7dbdbe23..729ff9c344 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScopeClaim.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScopeClaim.cs @@ -15,6 +15,11 @@ namespace Volo.Abp.IdentityServer.ApiResources } + public virtual bool Equals(Guid apiResourceId, [NotNull] string name, [NotNull] string type) + { + return ApiResourceId == apiResourceId && Name == name && Type == type; + } + protected internal ApiScopeClaim(Guid apiResourceId, [NotNull] string name, [NotNull] string type) : base(type) { diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiSecret.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiSecret.cs index 41c4bc53c2..e692183a71 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiSecret.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiSecret.cs @@ -10,7 +10,12 @@ namespace Volo.Abp.IdentityServer.ApiResources protected ApiSecret() { - + + } + + public virtual bool Equals(Guid apiResourceId, [NotNull] string value, string type = IdentityServerConstants.SecretTypes.SharedSecret) + { + return ApiResourceId == apiResourceId && Value == value && Type == type; } protected internal ApiSecret( From c5af4a0441b1dc2132d503b1f327ba7c08fa7eb9 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 8 Jan 2019 12:08:12 +0300 Subject: [PATCH 4/5] Update AbpTagHelperLocalizer.cs Resolved https://github.com/abpframework/abp/issues/720 --- .../TagHelpers/AbpTagHelperLocalizer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/AbpTagHelperLocalizer.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/AbpTagHelperLocalizer.cs index 35ad5a894d..72d32ce10b 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/AbpTagHelperLocalizer.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/AbpTagHelperLocalizer.cs @@ -20,14 +20,14 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers public string GetLocalizedText(string text, ModelExplorer explorer) { - var localizer = GetLocalizer(explorer); + var localizer = GetStringLocalizer(explorer); return localizer == null ? text : localizer[text].Value; } public IStringLocalizer GetLocalizer(ModelExplorer explorer) { - return GetLocalizer(explorer); + return GetStringLocalizer(explorer); } private IStringLocalizer GetStringLocalizer(ModelExplorer explorer) From 3eda49b792e585940c76d54a467575b58807fac7 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 8 Jan 2019 13:18:43 +0300 Subject: [PATCH 5/5] Update ClientRepository.cs --- .../Clients/ClientRepository.cs | 69 ------------------- 1 file changed, 69 deletions(-) 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 aee58475fe..62043562e8 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,75 +42,6 @@ namespace Volo.Abp.IdentityServer.Clients return await DbSet.CountAsync(); } - //public override async Task UpdateAsync(Client entity, bool autoSave = false, CancellationToken cancellationToken = default) - //{ - - // var secrets = DbContext.Set().Where(s => s.ClientId == entity.Id); - - // foreach (var secret in secrets) - // { - // DbContext.Set().Remove(secret); - // } - - // var claims = DbContext.Set().Where(s => s.ClientId == entity.Id); - - // foreach (var claim in claims) - // { - // DbContext.Set().Remove(claim); - // } - - // var grantTypes = DbContext.Set().Where(s => s.ClientId == entity.Id); - - // foreach (var grantType in grantTypes) - // { - // DbContext.Set().Remove(grantType); - // } - - // var restrictions = DbContext.Set().Where(s => s.ClientId == entity.Id); - - // foreach (var restriction in restrictions) - // { - // DbContext.Set().Remove(restriction); - // } - - // var properties = DbContext.Set().Where(s => s.ClientId == entity.Id); - - // foreach (var clientProperty in properties) - // { - // DbContext.Set().Remove(clientProperty); - // } - - // var scopes = DbContext.Set().Where(s => s.ClientId == entity.Id); - - // foreach (var scope in scopes) - // { - // DbContext.Set().Remove(scope); - // } - - // var corsOrigins = DbContext.Set().Where(s => s.ClientId == entity.Id); - - // foreach (var corsOrigin in corsOrigins) - // { - // DbContext.Set().Remove(corsOrigin); - // } - - // var redirectUris = DbContext.Set().Where(s => s.ClientId == entity.Id); - - // foreach (var redirectUri in redirectUris) - // { - // DbContext.Set().Remove(redirectUri); - // } - - // var postLogoutRedirectUris = DbContext.Set().Where(s => s.ClientId == entity.Id); - - // foreach (var postLogoutRedirectUri in postLogoutRedirectUris) - // { - // DbContext.Set().Remove(postLogoutRedirectUri); - // } - - // return await base.UpdateAsync(entity, autoSave, cancellationToken); - //} - public override IQueryable WithDetails() { return GetQueryable().IncludeDetails();