diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiScopeConsts.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiScopeConsts.cs index d52b953921..b61aa097f4 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiScopeConsts.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiScopeConsts.cs @@ -3,7 +3,5 @@ public class ApiScopeConsts { public const int NameMaxLength = 200; - public const int DisplayNameMaxLength = 200; - public const int DescriptionMaxLength = 1000; } -} \ No newline at end of file +} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Devices/DeviceFlowCodesEto.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Devices/DeviceFlowCodesEto.cs index f82af68bbf..66fa1f6eff 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Devices/DeviceFlowCodesEto.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Devices/DeviceFlowCodesEto.cs @@ -13,10 +13,14 @@ namespace Volo.Abp.IdentityServer.Devices public string SubjectId { get; set; } + public string SessionId { get; set; } + public string ClientId { get; set; } + public string Description { get; set; } + public DateTime? Expiration { get; set; } public string Data { get; set; } } -} \ No newline at end of file +} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AllowedSigningAlgorithmsConverter.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AllowedSigningAlgorithmsConverter.cs new file mode 100644 index 0000000000..ba4809feab --- /dev/null +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AllowedSigningAlgorithmsConverter.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using AutoMapper; + +namespace Volo.Abp.IdentityServer +{ + public class AllowedSigningAlgorithmsConverter : + IValueConverter, string>, + IValueConverter> + { + public static AllowedSigningAlgorithmsConverter Converter = new AllowedSigningAlgorithmsConverter(); + + public string Convert(ICollection sourceMember, ResolutionContext context) + { + if (sourceMember == null || !sourceMember.Any()) + { + return null; + } + return sourceMember.Aggregate((x, y) => $"{x},{y}"); + } + + public ICollection Convert(string sourceMember, ResolutionContext context) + { + var list = new HashSet(); + if (!String.IsNullOrWhiteSpace(sourceMember)) + { + sourceMember = sourceMember.Trim(); + foreach (var item in sourceMember.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Distinct()) + { + list.Add(item); + } + } + return list; + } + } +} 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 d2b1a630d4..dc795fb09b 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,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using IdentityServer4; @@ -18,9 +18,13 @@ namespace Volo.Abp.IdentityServer.ApiResources public virtual bool Enabled { get; set; } - public virtual List Secrets { get; protected set; } + public virtual string AllowedAccessTokenSigningAlgorithms { get; set; } - public virtual List Scopes { get; protected set; } + public virtual bool ShowInDiscoveryDocument { get; set; } = true; + + public virtual List Secrets { get; protected set; } + + public virtual List Scopes { get; protected set; } public virtual List UserClaims { get; protected set; } @@ -44,21 +48,21 @@ namespace Volo.Abp.IdentityServer.ApiResources Enabled = true; - Secrets = new List(); - Scopes = new List(); + Secrets = new List(); + Scopes = new List(); UserClaims = new List(); Properties = new Dictionary(); - Scopes.Add(new ApiScope(id, name, displayName, description)); + Scopes.Add(new ApiResourceScope(id, name)); } public virtual void AddSecret( - [NotNull] string value, + [NotNull] string value, DateTime? expiration = null, string type = IdentityServerConstants.SecretTypes.SharedSecret, string description = null) { - Secrets.Add(new ApiSecret(Id, value, expiration, type, description)); + Secrets.Add(new ApiResourceSecret(Id, value, expiration, type, description)); } public virtual void RemoveSecret([NotNull] string value, string type = IdentityServerConstants.SecretTypes.SharedSecret) @@ -66,22 +70,16 @@ namespace Volo.Abp.IdentityServer.ApiResources Secrets.RemoveAll(s => s.Value == value && s.Type == type); } - public virtual ApiSecret FindSecret([NotNull] string value, string type = IdentityServerConstants.SecretTypes.SharedSecret) + public virtual ApiResourceSecret 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) + public virtual ApiResourceScope AddScope([NotNull] string scope) { - var scope = new ApiScope(Id, name, displayName, description, required, emphasize, showInDiscoveryDocument); - Scopes.Add(scope); - return scope; + var apiResourceScope = new ApiResourceScope(Id, scope); + Scopes.Add(apiResourceScope); + return apiResourceScope; } public virtual void AddUserClaim([NotNull] string type) @@ -111,21 +109,17 @@ namespace Volo.Abp.IdentityServer.ApiResources public virtual void RemoveAllScopes() { - foreach (var scope in Scopes) - { - scope.RemoveAllUserClaims(); - } Scopes.Clear(); } - public virtual void RemoveScope(string name) + public virtual void RemoveScope(string scope) { - Scopes.RemoveAll(r => r.Name == name); + Scopes.RemoveAll(r => r.Scope == scope); } - public virtual ApiScope FindScope(string name) + public virtual ApiResourceScope FindScope(string scope) { - return Scopes.FirstOrDefault(r => r.Name == name); + return Scopes.FirstOrDefault(r => r.Scope == scope); } } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceScope.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceScope.cs new file mode 100644 index 0000000000..4da2beaa3f --- /dev/null +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceScope.cs @@ -0,0 +1,38 @@ +using System; +using JetBrains.Annotations; +using Volo.Abp.Domain.Entities; + +namespace Volo.Abp.IdentityServer.ApiResources +{ + public class ApiResourceScope : Entity + { + public virtual Guid ApiResourceId { get; protected set; } + + public virtual string Scope { get; set; } + + protected ApiResourceScope() + { + + } + + public virtual bool Equals(Guid apiResourceId, [NotNull] string scope) + { + return ApiResourceId == apiResourceId && Scope == scope; + } + + protected internal ApiResourceScope( + Guid apiResourceId, + [NotNull] string scope) + { + Check.NotNull(scope, nameof(scope)); + + ApiResourceId = apiResourceId; + Scope = scope; + } + + public override object[] GetKeys() + { + return new object[] { ApiResourceId, Scope }; + } + } +} 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/ApiResourceSecret.cs similarity index 74% rename from modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiSecret.cs rename to modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceSecret.cs index e692183a71..dcc6b04768 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/ApiResourceSecret.cs @@ -4,11 +4,11 @@ using JetBrains.Annotations; namespace Volo.Abp.IdentityServer.ApiResources { - public class ApiSecret : Secret + public class ApiResourceSecret : Secret { public virtual Guid ApiResourceId { get; protected set; } - protected ApiSecret() + protected ApiResourceSecret() { } @@ -18,16 +18,16 @@ namespace Volo.Abp.IdentityServer.ApiResources return ApiResourceId == apiResourceId && Value == value && Type == type; } - protected internal ApiSecret( + protected internal ApiResourceSecret( Guid apiResourceId, - [NotNull] string value, - DateTime? expiration = null, - string type = IdentityServerConstants.SecretTypes.SharedSecret, + [NotNull] string value, + DateTime? expiration = null, + string type = IdentityServerConstants.SecretTypes.SharedSecret, string description = null ) : base( - value, - expiration, - type, + value, + expiration, + type, description) { ApiResourceId = apiResourceId; @@ -38,4 +38,4 @@ namespace Volo.Abp.IdentityServer.ApiResources return new object[] { ApiResourceId, Type, Value }; } } -} \ No newline at end of file +} 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 1d22dec3dc..8e8605afa1 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,14 +1,14 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using JetBrains.Annotations; -using Volo.Abp.Domain.Entities; +using Volo.Abp.Domain.Entities.Auditing; namespace Volo.Abp.IdentityServer.ApiResources { - public class ApiScope : Entity + public class ApiScope : FullAuditedAggregateRoot { - public virtual Guid ApiResourceId { get; protected set; } + public virtual bool Enabled { get; set; } [NotNull] public virtual string Name { get; protected set; } @@ -25,44 +25,39 @@ namespace Volo.Abp.IdentityServer.ApiResources public virtual List UserClaims { get; protected set; } - public virtual Dictionary Properties { get; protected set; } + public virtual List Properties { get; protected set; } protected ApiScope() { } - public virtual bool Equals(Guid apiResourceId, [NotNull] string name) - { - return ApiResourceId == apiResourceId && Name == name; - } - protected internal ApiScope( - Guid apiResourceId, [NotNull] string name, string displayName = null, string description = null, bool required = false, bool emphasize = false, - bool showInDiscoveryDocument = true) + bool showInDiscoveryDocument = true, + bool enabled = true) { Check.NotNull(name, nameof(name)); - ApiResourceId = apiResourceId; Name = name; DisplayName = displayName ?? name; Description = description; Required = required; Emphasize = emphasize; ShowInDiscoveryDocument = showInDiscoveryDocument; + Enabled = enabled; UserClaims = new List(); - Properties = new Dictionary(); + Properties = new List(); } public virtual void AddUserClaim([NotNull] string type) { - UserClaims.Add(new ApiScopeClaim(ApiResourceId, Name, type)); + UserClaims.Add(new ApiScopeClaim(Id, Name, type)); } public virtual void RemoveAllUserClaims() @@ -79,10 +74,5 @@ namespace Volo.Abp.IdentityServer.ApiResources { 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 729ff9c344..e4444cbc8c 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 @@ -5,7 +5,7 @@ namespace Volo.Abp.IdentityServer.ApiResources { public class ApiScopeClaim : UserClaim { - public Guid ApiResourceId { get; protected set; } + public Guid ApiScopeId { get; protected set; } [NotNull] public string Name { get; protected set; } @@ -15,23 +15,23 @@ namespace Volo.Abp.IdentityServer.ApiResources } - public virtual bool Equals(Guid apiResourceId, [NotNull] string name, [NotNull] string type) + public virtual bool Equals(Guid apiScopeId, [NotNull] string name, [NotNull] string type) { - return ApiResourceId == apiResourceId && Name == name && Type == type; + return ApiScopeId == apiScopeId && Name == name && Type == type; } - protected internal ApiScopeClaim(Guid apiResourceId, [NotNull] string name, [NotNull] string type) + protected internal ApiScopeClaim(Guid apiScopeId, [NotNull] string name, [NotNull] string type) : base(type) { Check.NotNull(name, nameof(name)); - ApiResourceId = apiResourceId; + ApiScopeId = apiScopeId; Name = name; } public override object[] GetKeys() { - return new object[] { ApiResourceId, Name, Type }; + return new object[] { ApiScopeId, Name, Type }; } } -} \ No newline at end of file +} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScopeProperty.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScopeProperty.cs new file mode 100644 index 0000000000..38f34567a8 --- /dev/null +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScopeProperty.cs @@ -0,0 +1,39 @@ +using System; +using JetBrains.Annotations; +using Volo.Abp.Domain.Entities; + +namespace Volo.Abp.IdentityServer.ApiResources +{ + public class ApiScopeProperty : Entity + { + public virtual Guid ApiScopeId { get; set; } + + public virtual string Key { get; set; } + + public virtual string Value { get; set; } + + protected ApiScopeProperty() + { + + } + + public virtual bool Equals(Guid apiScopeId, [NotNull] string key, string value) + { + return ApiScopeId == apiScopeId && Key == key && Value == value; + } + + protected internal ApiScopeProperty(Guid apiScopeId, [NotNull] string key, [NotNull] string value) + { + Check.NotNull(key, nameof(key)); + + ApiScopeId = apiScopeId; + Key = key; + Value = value; + } + + public override object[] GetKeys() + { + return new object[] { ApiScopeId, Key }; + } + } +} 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 b7a53ad66f..82ba75a5fb 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 @@ -36,6 +36,8 @@ namespace Volo.Abp.IdentityServer.Clients public virtual bool AllowPlainTextPkce { get; set; } + public virtual bool RequireRequestObject { get; set; } + public virtual bool AllowAccessTokensViaBrowser { get; set; } public virtual string FrontChannelLogoutUri { get; set; } @@ -50,6 +52,8 @@ namespace Volo.Abp.IdentityServer.Clients public virtual int IdentityTokenLifetime { get; set; } + public virtual string AllowedIdentityTokenSigningAlgorithms { get; set; } + public virtual int AccessTokenLifetime { get; set; } public virtual int AuthorizationCodeLifetime { get; set; } @@ -118,8 +122,9 @@ namespace Volo.Abp.IdentityServer.Clients ProtocolType = IdentityServerConstants.ProtocolTypes.OpenIdConnect; RequireClientSecret = true; - RequireConsent = true; + RequireConsent = false; AllowRememberConsent = true; + RequirePkce = true; FrontChannelLogoutSessionRequired = true; BackChannelLogoutSessionRequired = true; IdentityTokenLifetime = 300; @@ -319,4 +324,4 @@ namespace Volo.Abp.IdentityServer.Clients 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/Devices/DeviceFlowCodes.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Devices/DeviceFlowCodes.cs index 3961de57a2..c24452a08b 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Devices/DeviceFlowCodes.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Devices/DeviceFlowCodes.cs @@ -11,8 +11,12 @@ namespace Volo.Abp.IdentityServer.Devices public virtual string SubjectId { get; set; } + public virtual string SessionId { get; set; } + public virtual string ClientId { get; set; } + public virtual string Description { get; set; } + public virtual DateTime? Expiration { get; set; } public virtual string Data { get; set; } @@ -28,4 +32,4 @@ namespace Volo.Abp.IdentityServer.Devices } } -} \ No newline at end of file +} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrant.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrant.cs index 4a2bccd456..1865ec748b 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrant.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrant.cs @@ -1,4 +1,4 @@ -using System; +using System; using Volo.Abp.Domain.Entities; namespace Volo.Abp.IdentityServer.Grants @@ -11,17 +11,23 @@ namespace Volo.Abp.IdentityServer.Grants public virtual string SubjectId { get; set; } + public virtual string SessionId { get; set; } + public virtual string ClientId { get; set; } + public virtual string Description { get; set; } + public virtual DateTime CreationTime { get; set; } public virtual DateTime? Expiration { get; set; } + public virtual DateTime? ConsumedTime { get; set; } + public virtual string Data { get; set; } protected PersistedGrant() { - + } public PersistedGrant(Guid id) @@ -29,4 +35,4 @@ namespace Volo.Abp.IdentityServer.Grants Id = id; } } -} \ No newline at end of file +} 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 f5d6f6c39c..246e1ddf98 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 @@ -22,9 +22,9 @@ namespace Volo.Abp.IdentityServer.IdentityResources public virtual bool ShowInDiscoveryDocument { get; set; } - public virtual List UserClaims { get; set; } + public virtual List UserClaims { get; set; } - public virtual Dictionary Properties { get; set; } + public virtual List Properties { get; set; } protected IdentityResource() { @@ -32,13 +32,13 @@ namespace Volo.Abp.IdentityServer.IdentityResources } public IdentityResource( - Guid id, - [NotNull] string name, - string displayName = null, - string description = null, - bool enabled = true, - bool required = false, - bool emphasize = false, + Guid id, + [NotNull] string name, + string displayName = null, + string description = null, + bool enabled = true, + bool required = false, + bool emphasize = false, bool showInDiscoveryDocument = true) { Check.NotNull(name, nameof(name)); @@ -51,9 +51,9 @@ namespace Volo.Abp.IdentityServer.IdentityResources Required = required; Emphasize = emphasize; ShowInDiscoveryDocument = showInDiscoveryDocument; - - UserClaims = new List(); - Properties = new Dictionary(); + + UserClaims = new List(); + Properties = new List(); } public IdentityResource(Guid id, IdentityServer4.Models.IdentityResource resource) @@ -66,13 +66,13 @@ namespace Volo.Abp.IdentityServer.IdentityResources Required = resource.Required; Emphasize = resource.Emphasize; ShowInDiscoveryDocument = resource.ShowInDiscoveryDocument; - UserClaims = resource.UserClaims.Select(claimType => new IdentityClaim(id, claimType)).ToList(); - Properties = resource.Properties.ToDictionary(x => x.Key, x => x.Value); + UserClaims = resource.UserClaims.Select(claimType => new IdentityResourceClaim(id, claimType)).ToList(); + Properties = resource.Properties.Select(x => new IdentityResourceProperty(Id, x.Key, x.Value)).ToList(); } public virtual void AddUserClaim([NotNull] string type) { - UserClaims.Add(new IdentityClaim(Id, type)); + UserClaims.Add(new IdentityResourceClaim(Id, type)); } public virtual void RemoveAllUserClaims() @@ -85,7 +85,7 @@ namespace Volo.Abp.IdentityServer.IdentityResources UserClaims.RemoveAll(c => c.Type == type); } - public virtual IdentityClaim FindUserClaim(string type) + public virtual IdentityResourceClaim FindUserClaim(string type) { return UserClaims.FirstOrDefault(c => c.Type == type); } 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/IdentityResourceClaim.cs similarity index 75% rename from modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityClaim.cs rename to modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceClaim.cs index 8b4a22b584..2bce3f66cf 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/IdentityResourceClaim.cs @@ -3,11 +3,11 @@ using JetBrains.Annotations; namespace Volo.Abp.IdentityServer.IdentityResources { - public class IdentityClaim : UserClaim + public class IdentityResourceClaim : UserClaim { public virtual Guid IdentityResourceId { get; set; } - protected IdentityClaim() + protected IdentityResourceClaim() { } @@ -17,7 +17,7 @@ namespace Volo.Abp.IdentityServer.IdentityResources return IdentityResourceId == identityResourceId && Type == type; } - protected internal IdentityClaim(Guid identityResourceId, [NotNull] string type) + protected internal IdentityResourceClaim(Guid identityResourceId, [NotNull] string type) : base(type) { IdentityResourceId = identityResourceId; @@ -28,4 +28,4 @@ namespace Volo.Abp.IdentityServer.IdentityResources return new object[] { IdentityResourceId, Type }; } } -} \ No newline at end of file +} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceProperty.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceProperty.cs new file mode 100644 index 0000000000..d351addfc2 --- /dev/null +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceProperty.cs @@ -0,0 +1,39 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using Volo.Abp.Domain.Entities; + +namespace Volo.Abp.IdentityServer.IdentityResources +{ + public class IdentityResourceProperty : Entity + { + public virtual Guid IdentityResourceId { get; set; } + + public virtual string Key { get; set; } + + public virtual string Value { get; set; } + + protected IdentityResourceProperty() + { + + } + + public virtual bool Equals(Guid identityResourceId, [NotNull] string key) + { + return IdentityResourceId == identityResourceId && Key == key; + } + + protected internal IdentityResourceProperty(Guid identityResourceId, [NotNull] string key, [NotNull] string value) + { + Check.NotNull(key, nameof(key)); + + IdentityResourceId = identityResourceId; + Key = key; + Value = value; + } + + public override object[] GetKeys() + { + return new object[] { IdentityResourceId, Key }; + } + } +} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityServerAutoMapperProfile.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityServerAutoMapperProfile.cs index 502e3fa1e2..17aae1b084 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityServerAutoMapperProfile.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityServerAutoMapperProfile.cs @@ -15,8 +15,6 @@ namespace Volo.Abp.IdentityServer { //TODO: Reverse maps will not used probably. Remove those will not used - CreateMap(); - CreateMap() .ConstructUsing(src => src.Origin) .ReverseMap() @@ -25,26 +23,53 @@ namespace Volo.Abp.IdentityServer CreateMap() .ForMember(dest => dest.ApiSecrets, opt => opt.MapFrom(src => src.Secrets)); + CreateMap(); + + //TODO: Why PersistedGrant mapping is in this profile? CreateMap().ReverseMap(); - CreateMap(); + CreateMap() + .ConstructUsing(src => new IdentityServer4.Models.IdentityResource()); + + CreateMap() + .ConstructUsing(x => x.Type) + .ReverseMap() + .ForMember(dest => dest.Type, opt => opt.MapFrom(src => src)); + + CreateMap>() + .ReverseMap(); CreateMap() .ConstructUsing(src => src.Type) .ReverseMap() .ForMember(dest => dest.Type, opt => opt.MapFrom(src => src)); - CreateMap(); + CreateMap() + .ConstructUsing(x => x.Scope) + .ReverseMap() + .ForMember(dest => dest.Scope, opt => opt.MapFrom(src => src)); - CreateMap(); + CreateMap>() + .ReverseMap(); + + CreateMap() + .ConstructUsing(x => x.Type) + .ReverseMap() + .ForMember(dest => dest.Type, opt => opt.MapFrom(src => src)); + + CreateMap(MemberList.Destination) + .ConstructUsing(src => new IdentityServer4.Models.ApiScope()) + .ReverseMap(); CreateMap>() .ReverseMap(); CreateMap() .ForMember(dest => dest.ProtocolType, opt => opt.Condition(srs => srs != null)) - .ReverseMap(); + .ForMember(x => x.AllowedIdentityTokenSigningAlgorithms, opts => opts.ConvertUsing(AllowedSigningAlgorithmsConverter.Converter, x => x.AllowedIdentityTokenSigningAlgorithms)) + .ReverseMap() + .ForMember(x => x.AllowedIdentityTokenSigningAlgorithms, opts => opts.ConvertUsing(AllowedSigningAlgorithmsConverter.Converter, x => x.AllowedIdentityTokenSigningAlgorithms)); CreateMap() .ConstructUsing(src => src.Origin) @@ -60,6 +85,10 @@ namespace Volo.Abp.IdentityServer .ConstructUsing(src => new Claim(src.Type, src.Value)) .ReverseMap(); + CreateMap(MemberList.None) + .ConstructUsing(src => new IdentityServer4.Models.ClientClaim(src.Type, src.Value, ClaimValueTypes.String)) + .ReverseMap(); + CreateMap() .ConstructUsing(src => src.Scope) .ReverseMap() @@ -89,6 +118,7 @@ namespace Volo.Abp.IdentityServer CreateMap(); CreateMap(); CreateMap(); + } } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ResourceStore.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ResourceStore.cs index 6252be400c..975fc7f801 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ResourceStore.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ResourceStore.cs @@ -6,7 +6,6 @@ using IdentityServer4.Stores; using Volo.Abp.IdentityServer.ApiResources; using Volo.Abp.IdentityServer.IdentityResources; using Volo.Abp.ObjectMapping; -using ApiScope = Volo.Abp.IdentityServer.ApiResources.ApiScope; namespace Volo.Abp.IdentityServer { diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/AbpIdentityServerEfCoreQueryableExtensions.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/AbpIdentityServerEfCoreQueryableExtensions.cs index a72cadb943..6e47d461e4 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/AbpIdentityServerEfCoreQueryableExtensions.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/AbpIdentityServerEfCoreQueryableExtensions.cs @@ -18,20 +18,7 @@ namespace Volo.Abp.IdentityServer return queryable .Include(x => x.Secrets) .Include(x => x.UserClaims) - .Include(x => x.Scopes) - .ThenInclude(s => s.UserClaims); - } - - public static IQueryable IncludeDetails(this IQueryable queryable, bool include = true) - { - if (!include) - { - return queryable; - } - - return queryable - .Include(x => x.UserClaims) - .Include(x => x.Properties); + .Include(x => x.Scopes); } public static IQueryable IncludeDetails(this IQueryable queryable, bool include = true) diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResources/ApiResourceRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResources/ApiResourceRepository.cs index d12a8208c2..4d0baf7702 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResources/ApiResourceRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResources/ApiResourceRepository.cs @@ -35,7 +35,7 @@ namespace Volo.Abp.IdentityServer.ApiResources CancellationToken cancellationToken = default) { var query = from api in DbSet.IncludeDetails(includeDetails) - where api.Scopes.Any(x => scopeNames.Contains(x.Name)) + where api.Scopes.Any(x => scopeNames.Contains(x.Scope)) select api; return await query.ToListAsync(GetCancellationToken(cancellationToken)); @@ -74,18 +74,18 @@ namespace Volo.Abp.IdentityServer.ApiResources public override async Task DeleteAsync(Guid id, bool autoSave = false, CancellationToken cancellationToken = default) { - var scopeClaims = DbContext.Set().Where(sc => sc.ApiResourceId == id); + var scopeClaims = DbContext.Set().Where(sc => sc.ApiScopeId == id); foreach (var scopeClaim in scopeClaims) { DbContext.Set().Remove(scopeClaim); } - var scopes = DbContext.Set().Where(s => s.ApiResourceId == id); + var scopes = DbContext.Set().Where(s => s.ApiResourceId == id); foreach (var scope in scopes) { - DbContext.Set().Remove(scope); + DbContext.Set().Remove(scope); } await base.DeleteAsync(id, autoSave, cancellationToken); diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResources/ApiScopeRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResources/ApiScopeRepository.cs index dba7405a06..6df9f5b90a 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResources/ApiScopeRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResources/ApiScopeRepository.cs @@ -19,9 +19,7 @@ namespace Volo.Abp.IdentityServer.ApiResources public async Task> GetListByNameAsync(string[] scopeNames, bool includeDetails = false, CancellationToken cancellationToken = default) { - var query = from scope in DbSet.IncludeDetails(includeDetails) - where scopeNames.Contains(scope.Name) - select scope; + var query = from scope in DbSet where scopeNames.Contains(scope.Name) select scope; return await query.ToListAsync(GetCancellationToken(cancellationToken)); } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IIdentityServerDbContext.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IIdentityServerDbContext.cs index 52ba7c8e6c..93624174f9 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IIdentityServerDbContext.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IIdentityServerDbContext.cs @@ -14,17 +14,17 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore { DbSet ApiResources { get; set; } - DbSet ApiSecrets { get; set; } + DbSet ApiSecrets { get; set; } DbSet ApiResourceClaims { get; set; } - DbSet ApiScopes { get; set; } + DbSet ApiScopes { get; set; } DbSet ApiScopeClaims { get; set; } DbSet IdentityResources { get; set; } - DbSet IdentityClaims { get; set; } + DbSet IdentityClaims { get; set; } DbSet Clients { get; set; } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContext.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContext.cs index f63cd6bf1c..84ec1f802a 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContext.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/IdentityServerDbContext.cs @@ -14,17 +14,17 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore { public DbSet ApiResources { get; set; } - public DbSet ApiSecrets { get; set; } + public DbSet ApiSecrets { get; set; } public DbSet ApiResourceClaims { get; set; } - public DbSet ApiScopes { get; set; } + public DbSet ApiScopes { get; set; } public DbSet ApiScopeClaims { get; set; } public DbSet IdentityResources { get; set; } - public DbSet IdentityClaims { get; set; } + public DbSet IdentityClaims { get; set; } public DbSet Clients { get; set; } 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 8acb8a9539..54b91e9dcc 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 @@ -81,8 +81,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore if (IsDatabaseProvider(builder, options, EfCoreDatabaseProvider.MySql)) { ClientRedirectUriConsts.RedirectUriMaxLengthValue = 300; - } - + } + b.Property(x => x.RedirectUri).HasMaxLength(ClientRedirectUriConsts.RedirectUriMaxLengthValue).IsRequired(); }); @@ -97,8 +97,8 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore if (IsDatabaseProvider(builder, options, EfCoreDatabaseProvider.MySql)) { ClientPostLogoutRedirectUriConsts.PostLogoutRedirectUriMaxLengthValue = 300; - } - + } + b.Property(x => x.PostLogoutRedirectUri) .HasMaxLength(ClientPostLogoutRedirectUriConsts.PostLogoutRedirectUriMaxLengthValue) .IsRequired(); @@ -129,7 +129,7 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore { SecretConsts.ValueMaxLengthValue = 300; } - + b.Property(x => x.Value).HasMaxLength(SecretConsts.ValueMaxLengthValue).IsRequired(); b.Property(x => x.Description).HasMaxLength(SecretConsts.DescriptionMaxLength); @@ -195,9 +195,9 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore if (IsDatabaseProvider(builder, options, EfCoreDatabaseProvider.MySql)) { - PersistedGrantConsts.DataMaxLengthValue = 10000; //TODO: MySQL accepts 20.000. We can consider to change in v3.0. + PersistedGrantConsts.DataMaxLengthValue = 10000; //TODO: MySQL accepts 20.000. We can consider to change in v3.0. } - + b.Property(x => x.Data).HasMaxLength(PersistedGrantConsts.DataMaxLengthValue).IsRequired(); b.HasKey(x => x.Key); //TODO: What about Id!!! @@ -215,16 +215,14 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore b.Property(x => x.Name).HasMaxLength(IdentityResourceConsts.NameMaxLength).IsRequired(); b.Property(x => x.DisplayName).HasMaxLength(IdentityResourceConsts.DisplayNameMaxLength); b.Property(x => x.Description).HasMaxLength(IdentityResourceConsts.DescriptionMaxLength); - b.Property(x => x.Properties) - .HasConversion(new AbpJsonValueConverter>()) - .Metadata.SetValueComparer(new AbpDictionaryValueComparer()); b.HasMany(x => x.UserClaims).WithOne().HasForeignKey(x => x.IdentityResourceId).IsRequired(); + b.HasMany(x => x.Properties).WithOne().HasForeignKey(x => x.IdentityResourceId).IsRequired(); }); - builder.Entity(b => + builder.Entity(b => { - b.ToTable(options.TablePrefix + "IdentityClaims", options.Schema); + b.ToTable(options.TablePrefix + "IdentityResourceClaims", options.Schema); b.ConfigureByConvention(); @@ -233,6 +231,18 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore b.Property(x => x.Type).HasMaxLength(UserClaimConsts.TypeMaxLength).IsRequired(); }); + builder.Entity(b => + { + b.ToTable(options.TablePrefix + "IdentityResourceProperties", options.Schema); + + b.ConfigureByConvention(); + + b.HasKey(x => new {x.IdentityResourceId, x.Key}); + + b.Property(x => x.Key).HasMaxLength(250).IsRequired(); + b.Property(x => x.Value).HasMaxLength(2000).IsRequired(); + }); + builder.Entity(b => { b.ToTable(options.TablePrefix + "ApiResources", options.Schema); @@ -251,9 +261,9 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore b.HasMany(x => x.UserClaims).WithOne().HasForeignKey(x => x.ApiResourceId).IsRequired(); }); - builder.Entity(b => + builder.Entity(b => { - b.ToTable(options.TablePrefix + "ApiSecrets", options.Schema); + b.ToTable(options.TablePrefix + "ApiResourceSecrets", options.Schema); b.ConfigureByConvention(); @@ -265,14 +275,14 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore if (IsDatabaseProvider(builder, options, EfCoreDatabaseProvider.MySql, EfCoreDatabaseProvider.Oracle)) { SecretConsts.ValueMaxLengthValue = 300; - } - + } + b.Property(x => x.Value).HasMaxLength(SecretConsts.ValueMaxLengthValue).IsRequired(); }); builder.Entity(b => { - b.ToTable(options.TablePrefix + "ApiClaims", options.Schema); + b.ToTable(options.TablePrefix + "ApiResourceClaims", options.Schema); b.ConfigureByConvention(); @@ -281,19 +291,33 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore b.Property(x => x.Type).HasMaxLength(UserClaimConsts.TypeMaxLength).IsRequired(); }); + builder.Entity(b => + { + b.ToTable(options.TablePrefix + "ApiResourceScopes", options.Schema); + + b.ConfigureByConvention(); + + b.HasKey(x => new {x.ApiResourceId, x.Scope}); + + b.Property(x => x.Scope).HasMaxLength(ApiScopeConsts.NameMaxLength).IsRequired(); + }); + builder.Entity(b => { b.ToTable(options.TablePrefix + "ApiScopes", options.Schema); b.ConfigureByConvention(); - b.HasKey(x => new {x.ApiResourceId, x.Name}); + b.Property(x => x.Name).HasMaxLength(200).IsRequired(); + b.Property(x => x.DisplayName).HasMaxLength(200); + b.Property(x => x.Description).HasMaxLength(1000); - b.Property(x => x.Name).HasMaxLength(ApiScopeConsts.NameMaxLength).IsRequired(); - b.Property(x => x.DisplayName).HasMaxLength(ApiScopeConsts.DisplayNameMaxLength); - b.Property(x => x.Description).HasMaxLength(ApiScopeConsts.DescriptionMaxLength); + b.HasIndex(x => x.Name).IsUnique(); - b.HasMany(x => x.UserClaims).WithOne().HasForeignKey(x => new {x.ApiResourceId, x.Name}).IsRequired(); + b.HasMany(x => x.UserClaims).WithOne().HasForeignKey(x => x.ApiScopeId).IsRequired(); + + //Identity Server does not configure the relationship of Properties + //b.HasMany(x => x.Properties).WithOne().HasForeignKey(x => x.ApiScopeId).IsRequired(); }); builder.Entity(b => @@ -302,12 +326,25 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore b.ConfigureByConvention(); - b.HasKey(x => new {x.ApiResourceId, x.Name, x.Type}); + b.HasKey(x => new {x.ApiScopeId, x.Name, x.Type}); b.Property(x => x.Type).HasMaxLength(UserClaimConsts.TypeMaxLength).IsRequired(); b.Property(x => x.Name).HasMaxLength(ApiScopeConsts.NameMaxLength).IsRequired(); }); + builder.Entity(b => + { + b.ToTable(options.TablePrefix + "ApiScopeProperties", options.Schema); + + b.ConfigureByConvention(); + + b.HasKey(x => new {x.ApiScopeId, x.Key}); + + b.Property(x => x.Key).HasMaxLength(250).IsRequired(); + //oracle? + b.Property(x => x.Value).HasMaxLength(2000).IsRequired(); + }); + builder.Entity(b => { b.ToTable(options.TablePrefix + "DeviceFlowCodes", options.Schema); @@ -344,4 +381,4 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore return false; } } -} \ No newline at end of file +} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Grants/PersistedGrantRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Grants/PersistedGrantRepository.cs index 7a0bf0fbba..9b54a4cf24 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Grants/PersistedGrantRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Grants/PersistedGrantRepository.cs @@ -74,10 +74,9 @@ namespace Volo.Abp.IdentityServer.Grants string clientId, string type) { - //IDS TODO: add SessionId to entity return DbSet .WhereIf(!subjectId.IsNullOrWhiteSpace(), x => x.SubjectId == subjectId) - // .WhereIf(!sessionId.IsNullOrWhiteSpace(), x => x.SessionId == sessionId) + .WhereIf(!sessionId.IsNullOrWhiteSpace(), x => x.SessionId == sessionId) .WhereIf(!clientId.IsNullOrWhiteSpace(), x => x.ClientId == clientId) .WhereIf(!type.IsNullOrWhiteSpace(), x => x.Type == type); } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiResourceRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiResourceRepository.cs index de694a37c5..20d55b3d0e 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiResourceRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiResourceRepository.cs @@ -30,7 +30,7 @@ namespace Volo.Abp.IdentityServer.MongoDB CancellationToken cancellationToken = default) { return await GetMongoQueryable() - .Where(ar => ar.Scopes.Any(x => scopeNames.Contains(x.Name))) + .Where(ar => ar.Scopes.Any(x => scopeNames.Contains(x.Scope))) .ToListAsync(GetCancellationToken(cancellationToken)); } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoPersistedGrantRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoPersistedGrantRepository.cs index 11559b7707..6af1f5488d 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoPersistedGrantRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoPersistedGrantRepository.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading; using System.Threading.Tasks; using MongoDB.Driver; @@ -8,6 +9,7 @@ using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.IdentityServer.Grants; using Volo.Abp.MongoDB; + namespace Volo.Abp.IdentityServer.MongoDB { public class MongoPersistentGrantRepository : MongoDbRepository, IPersistentGrantRepository @@ -85,12 +87,11 @@ namespace Volo.Abp.IdentityServer.MongoDB string clientId, string type) { - //IDS TODO: add SessionId to entity return GetMongoQueryable() - .WhereIf(!subjectId.IsNullOrWhiteSpace(), x => x.SubjectId == subjectId) - // .WhereIf(!sessionId.IsNullOrWhiteSpace(), x => x.SessionId == sessionId) - .WhereIf(!clientId.IsNullOrWhiteSpace(), x => x.ClientId == clientId) - .WhereIf(!type.IsNullOrWhiteSpace(), x => x.Type == type) + .WhereIf>(!subjectId.IsNullOrWhiteSpace(), x => x.SubjectId == subjectId) + .WhereIf>(!sessionId.IsNullOrWhiteSpace(), x => x.SessionId == sessionId) + .WhereIf>(!clientId.IsNullOrWhiteSpace(), x => x.ClientId == clientId) + .WhereIf>(!type.IsNullOrWhiteSpace(), x => x.Type == type) .As>(); } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Clients/IdentityResourceStore_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Clients/IdentityResourceStore_Tests.cs index ef74266285..a196fd7534 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Clients/IdentityResourceStore_Tests.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Clients/IdentityResourceStore_Tests.cs @@ -19,13 +19,13 @@ namespace Volo.Abp.IdentityServer.Clients } [Fact] - public async Task FindApiResourceAsync_Should_Return_Null_If_Not_Found() + public async Task FindApiResourceAsync_Should_Return_Empty_If_Not_Found() { //Act var resource = await _resourceStore.FindApiResourcesByNameAsync(new []{"non-existing-name"}); //Assert - resource.ShouldBeNull(); + resource.ShouldBeEmpty(); } [Fact] @@ -60,7 +60,7 @@ namespace Volo.Abp.IdentityServer.Clients public async Task FindIdentityResourcesByScopeAsync_Should_Return_For_Given_Scopes() { //Act - var identityResourcesByScope = (await _resourceStore.FindApiResourcesByScopeNameAsync(new List + var identityResourcesByScope = (await _resourceStore.FindIdentityResourcesByScopeNameAsync(new List { "Test-Identity-Resource-Name-1" })).ToArray(); @@ -69,9 +69,7 @@ namespace Volo.Abp.IdentityServer.Clients identityResourcesByScope.Length.ShouldBe(1); identityResourcesByScope.First().DisplayName.ShouldBe("Test-Identity-Resource-DisplayName-1"); identityResourcesByScope.First().Description.ShouldBe("Test-Identity-Resource-Description-1"); - - //IDS TODO: - //identityResourcesByScope.First().Required.ShouldBe(true); + identityResourcesByScope.First().Required.ShouldBe(true); } [Fact] diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs index 0d87a2fd19..d2efa7b352 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs @@ -27,7 +27,7 @@ namespace Volo.Abp.IdentityServer IClientRepository clientRepository, IGuidGenerator guidGenerator, IPersistentGrantRepository persistentGrantRepository, - IApiResourceRepository apiResourceRepository, + IApiResourceRepository apiResourceRepository, IIdentityResourceRepository identityResourceRepository) { _clientRepository = clientRepository; @@ -51,7 +51,7 @@ namespace Volo.Abp.IdentityServer { ProtocolType = "TestProtocol-42" }; - + client42.AddCorsOrigin("Origin1"); client42.AddScope("api1"); @@ -108,7 +108,8 @@ namespace Volo.Abp.IdentityServer }; apiResource.AddSecret("secret".Sha256()); - apiResource.AddScope("Test-ApiResource-ApiScope-Name-1", "Test-ApiResource-ApiScope-DisplayName-1"); + apiResource.AddScope("Test-ApiResource-ApiScope-Name-1"); + apiResource.AddScope("Test-ApiResource-ApiScope-DisplayName-1"); apiResource.AddUserClaim("Test-ApiResource-Claim-Type-1"); await _apiResourceRepository.InsertAsync(apiResource); diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs index c36fef2d58..21e7123abe 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs @@ -91,6 +91,7 @@ namespace Volo.Abp.IdentityServer { Key = "PersistedGrantKey1", SubjectId = "PersistedGrantSubjectId1", + SessionId = "PersistedGrantSessionId1", ClientId = "PersistedGrantClientId1", Type = "PersistedGrantType1", Data = "" @@ -147,9 +148,9 @@ namespace Volo.Abp.IdentityServer apiResource.Description = nameof(apiResource.Description); apiResource.DisplayName = nameof(apiResource.DisplayName); - apiResource.AddScope(nameof(ApiScope.Name)); + apiResource.AddScope(nameof(ApiResourceScope.Scope)); apiResource.AddUserClaim(nameof(ApiResourceClaim.Type)); - apiResource.AddSecret(nameof(ApiSecret.Value)); + apiResource.AddSecret(nameof(ApiResourceSecret.Value)); await _apiResourceRepository.InsertAsync(apiResource); await _apiResourceRepository.InsertAsync(new ApiResource(_guidGenerator.Create(), "NewApiResource2")); diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/PersistentGrantRepository_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/PersistentGrantRepository_Tests.cs index 91e14bbace..73e2537207 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/PersistentGrantRepository_Tests.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/PersistentGrantRepository_Tests.cs @@ -36,7 +36,7 @@ namespace Volo.Abp.IdentityServer [Fact] public async Task DeleteBySubjectIdAndClientId() { - await _persistentGrantRepository.DeleteAsync("PersistedGrantSubjectId1", "PersistedGrantClientId1"); + await _persistentGrantRepository.DeleteAsync("PersistedGrantSubjectId1", "PersistedGrantSessionId1", "PersistedGrantClientId1"); var persistedGrants = await _persistentGrantRepository.GetListAsync(); persistedGrants.ShouldNotBeEmpty();