diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/AbpIdentityServerDomainSharedModule.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/AbpIdentityServerDomainSharedModule.cs index d56968ba5d..9dec892834 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/AbpIdentityServerDomainSharedModule.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/AbpIdentityServerDomainSharedModule.cs @@ -6,32 +6,31 @@ using Volo.Abp.Validation; using Volo.Abp.Validation.Localization; using Volo.Abp.VirtualFileSystem; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +[DependsOn( + typeof(AbpValidationModule) + )] +public class AbpIdentityServerDomainSharedModule : AbpModule { - [DependsOn( - typeof(AbpValidationModule) - )] - public class AbpIdentityServerDomainSharedModule : AbpModule + public override void ConfigureServices(ServiceConfigurationContext context) { - public override void ConfigureServices(ServiceConfigurationContext context) + Configure(options => { - Configure(options => - { - options.FileSets.AddEmbedded(); - }); + options.FileSets.AddEmbedded(); + }); - Configure(options => - { - options.Resources.Add("en") - .AddBaseTypes( - typeof(AbpValidationResource) - ).AddVirtualJson("/Volo/Abp/IdentityServer/Localization/Resources"); - }); + Configure(options => + { + options.Resources.Add("en") + .AddBaseTypes( + typeof(AbpValidationResource) + ).AddVirtualJson("/Volo/Abp/IdentityServer/Localization/Resources"); + }); - Configure(options => - { - options.MapCodeNamespace("Volo.IdentityServer", typeof(AbpIdentityServerResource)); - }); - } + Configure(options => + { + options.MapCodeNamespace("Volo.IdentityServer", typeof(AbpIdentityServerResource)); + }); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiResourceConsts.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiResourceConsts.cs index 05719fbc8f..5ad13cd4ea 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiResourceConsts.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiResourceConsts.cs @@ -1,13 +1,12 @@ -namespace Volo.Abp.IdentityServer.ApiResources +namespace Volo.Abp.IdentityServer.ApiResources; + +public class ApiResourceConsts { - public class ApiResourceConsts - { - public static int NameMaxLength { get; set; } = 200; + public static int NameMaxLength { get; set; } = 200; - public static int DisplayNameMaxLength { get; set; } = 200; + public static int DisplayNameMaxLength { get; set; } = 200; - public static int DescriptionMaxLength { get; set; } = 1000; + public static int DescriptionMaxLength { get; set; } = 1000; - public static int AllowedAccessTokenSigningAlgorithmsMaxLength { get; set; } = 100; - } + public static int AllowedAccessTokenSigningAlgorithmsMaxLength { get; set; } = 100; } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiResourceEto.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiResourceEto.cs index 333201d284..f91f10d2f3 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiResourceEto.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiResourceEto.cs @@ -1,20 +1,19 @@ using System; using JetBrains.Annotations; -namespace Volo.Abp.IdentityServer.ApiResources +namespace Volo.Abp.IdentityServer.ApiResources; + +[Serializable] +public class ApiResourceEto { - [Serializable] - public class ApiResourceEto - { - public Guid Id { get; set; } + public Guid Id { get; set; } - [NotNull] - public string Name { get; set; } + [NotNull] + public string Name { get; set; } - public string DisplayName { get; set; } + public string DisplayName { get; set; } - public string Description { get; set; } + public string Description { get; set; } - public bool Enabled { get; set; } - } + public bool Enabled { get; set; } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiResourcePropertyConsts.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiResourcePropertyConsts.cs index 2bcf8643d1..ac7403f400 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiResourcePropertyConsts.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiResourcePropertyConsts.cs @@ -1,9 +1,8 @@ -namespace Volo.Abp.IdentityServer.ApiResources +namespace Volo.Abp.IdentityServer.ApiResources; + +public class ApiResourcePropertyConsts { - public class ApiResourcePropertyConsts - { - public static int KeyMaxLength { get; set; } = 250; + public static int KeyMaxLength { get; set; } = 250; - public static int ValueMaxLength { get; set; } = 2000; - } + public static int ValueMaxLength { get; set; } = 2000; } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiResourceScopeConsts.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiResourceScopeConsts.cs index f64c8d79cf..169609dca1 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiResourceScopeConsts.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiResourceScopeConsts.cs @@ -1,7 +1,6 @@ -namespace Volo.Abp.IdentityServer.ApiResources +namespace Volo.Abp.IdentityServer.ApiResources; + +public class ApiResourceScopeConsts { - public class ApiResourceScopeConsts - { - public static int ScopeMaxLength { get; set; } = 200; - } + public static int ScopeMaxLength { get; set; } = 200; } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiResourceSecretConsts.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiResourceSecretConsts.cs index 523bc147b1..52ab98cf6f 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiResourceSecretConsts.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiResourceSecretConsts.cs @@ -1,20 +1,19 @@ -namespace Volo.Abp.IdentityServer.ApiResources +namespace Volo.Abp.IdentityServer.ApiResources; + +public class ApiResourceSecretConsts { - public class ApiResourceSecretConsts - { - /// - /// Default value: 250 - /// - public static int TypeMaxLength { get; set; } = 250; + /// + /// Default value: 250 + /// + public static int TypeMaxLength { get; set; } = 250; - /// - /// Default value: 4000 - /// - public static int ValueMaxLength { get; set; } = 4000; + /// + /// Default value: 4000 + /// + public static int ValueMaxLength { get; set; } = 4000; - /// - /// Default value: 1000 - /// - public static int DescriptionMaxLength { get; set; } = 1000; - } + /// + /// Default value: 1000 + /// + public static int DescriptionMaxLength { get; set; } = 1000; } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiScopes/ApiScopeConsts.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiScopes/ApiScopeConsts.cs index 78f59a1eff..ecfb78e0d2 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiScopes/ApiScopeConsts.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiScopes/ApiScopeConsts.cs @@ -1,11 +1,10 @@ -namespace Volo.Abp.IdentityServer.ApiScopes +namespace Volo.Abp.IdentityServer.ApiScopes; + +public class ApiScopeConsts { - public class ApiScopeConsts - { - public static int NameMaxLength { get; set; } = 200; + public static int NameMaxLength { get; set; } = 200; - public static int DisplayNameMaxLength { get; set; } = 200; + public static int DisplayNameMaxLength { get; set; } = 200; - public static int DescriptionMaxLength { get; set; } = 1000; - } + public static int DescriptionMaxLength { get; set; } = 1000; } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiScopes/ApiScopePropertyConsts.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiScopes/ApiScopePropertyConsts.cs index ef4f83af07..fccc363702 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiScopes/ApiScopePropertyConsts.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiScopes/ApiScopePropertyConsts.cs @@ -1,9 +1,8 @@ -namespace Volo.Abp.IdentityServer.ApiScopes +namespace Volo.Abp.IdentityServer.ApiScopes; + +public class ApiScopePropertyConsts { - public class ApiScopePropertyConsts - { - public static int KeyMaxLength { get; set; } = 250; + public static int KeyMaxLength { get; set; } = 250; - public static int ValueMaxLength { get; set; } = 2000; - } + public static int ValueMaxLength { get; set; } = 2000; } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientClaimConsts.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientClaimConsts.cs index e6a8cc5c5f..3f774a2a8a 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientClaimConsts.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientClaimConsts.cs @@ -1,9 +1,8 @@ -namespace Volo.Abp.IdentityServer.Clients +namespace Volo.Abp.IdentityServer.Clients; + +public class ClientClaimConsts { - public class ClientClaimConsts - { - public static int TypeMaxLength { get; set; } = 250; + public static int TypeMaxLength { get; set; } = 250; - public static int ValueMaxLength { get; set; } = 250; - } + public static int ValueMaxLength { get; set; } = 250; } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientConsts.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientConsts.cs index e76411d0ed..8f600c1789 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientConsts.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientConsts.cs @@ -1,29 +1,28 @@ -namespace Volo.Abp.IdentityServer.Clients +namespace Volo.Abp.IdentityServer.Clients; + +public class ClientConsts { - public class ClientConsts - { - public static int ClientIdMaxLength { get; set; } = 200; + public static int ClientIdMaxLength { get; set; } = 200; - public static int ProtocolTypeMaxLength { get; set; } = 200; + public static int ProtocolTypeMaxLength { get; set; } = 200; - public static int ClientNameMaxLength { get; set; } = 200; + public static int ClientNameMaxLength { get; set; } = 200; - public static int ClientUriMaxLength { get; set; } = 2000; + public static int ClientUriMaxLength { get; set; } = 2000; - public static int LogoUriMaxLength { get; set; } = 2000; + public static int LogoUriMaxLength { get; set; } = 2000; - public static int DescriptionMaxLength { get; set; } = 1000; + public static int DescriptionMaxLength { get; set; } = 1000; - public static int FrontChannelLogoutUriMaxLength { get; set; } = 2000; + public static int FrontChannelLogoutUriMaxLength { get; set; } = 2000; - public static int BackChannelLogoutUriMaxLength { get; set; } = 2000; + public static int BackChannelLogoutUriMaxLength { get; set; } = 2000; - public static int ClientClaimsPrefixMaxLength { get; set; } = 200; + public static int ClientClaimsPrefixMaxLength { get; set; } = 200; - public static int PairWiseSubjectSaltMaxLength { get; set; } = 200; + public static int PairWiseSubjectSaltMaxLength { get; set; } = 200; - public static int UserCodeTypeMaxLength { get; set; } = 100; + public static int UserCodeTypeMaxLength { get; set; } = 100; - public static int AllowedIdentityTokenSigningAlgorithms { get; set; } = 100; - } + public static int AllowedIdentityTokenSigningAlgorithms { get; set; } = 100; } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientCorsOriginConsts.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientCorsOriginConsts.cs index 2ec28df4a2..df4b9dccb8 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientCorsOriginConsts.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientCorsOriginConsts.cs @@ -1,7 +1,6 @@ -namespace Volo.Abp.IdentityServer.Clients +namespace Volo.Abp.IdentityServer.Clients; + +public class ClientCorsOriginConsts { - public class ClientCorsOriginConsts - { - public static int OriginMaxLength { get; set; } = 150; - } + public static int OriginMaxLength { get; set; } = 150; } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientEto.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientEto.cs index e5957eef5a..f002e67c89 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientEto.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientEto.cs @@ -1,84 +1,83 @@ using System; -namespace Volo.Abp.IdentityServer.Clients +namespace Volo.Abp.IdentityServer.Clients; + +[Serializable] +public class ClientEto { - [Serializable] - public class ClientEto - { - public Guid Id { get; set; } + public Guid Id { get; set; } - public string ClientId { get; set; } + public string ClientId { get; set; } - public string ClientName { get; set; } + public string ClientName { get; set; } - public string Description { get; set; } + public string Description { get; set; } - public string ClientUri { get; set; } + public string ClientUri { get; set; } - public string LogoUri { get; set; } + public string LogoUri { get; set; } - public bool Enabled { get; set; } = true; + public bool Enabled { get; set; } = true; - public string ProtocolType { get; set; } + public string ProtocolType { get; set; } - public bool RequireClientSecret { get; set; } + public bool RequireClientSecret { get; set; } - public bool RequireConsent { get; set; } + public bool RequireConsent { get; set; } - public bool AllowRememberConsent { get; set; } + public bool AllowRememberConsent { get; set; } - public bool AlwaysIncludeUserClaimsInIdToken { get; set; } + public bool AlwaysIncludeUserClaimsInIdToken { get; set; } - public bool RequirePkce { get; set; } + public bool RequirePkce { get; set; } - public bool AllowPlainTextPkce { get; set; } + public bool AllowPlainTextPkce { get; set; } - public bool AllowAccessTokensViaBrowser { get; set; } + public bool AllowAccessTokensViaBrowser { get; set; } - public string FrontChannelLogoutUri { get; set; } + public string FrontChannelLogoutUri { get; set; } - public bool FrontChannelLogoutSessionRequired { get; set; } + public bool FrontChannelLogoutSessionRequired { get; set; } - public string BackChannelLogoutUri { get; set; } + public string BackChannelLogoutUri { get; set; } - public bool BackChannelLogoutSessionRequired { get; set; } + public bool BackChannelLogoutSessionRequired { get; set; } - public bool AllowOfflineAccess { get; set; } + public bool AllowOfflineAccess { get; set; } - public int IdentityTokenLifetime { get; set; } + public int IdentityTokenLifetime { get; set; } - public int AccessTokenLifetime { get; set; } + public int AccessTokenLifetime { get; set; } - public int AuthorizationCodeLifetime { get; set; } + public int AuthorizationCodeLifetime { get; set; } - public int? ConsentLifetime { get; set; } + public int? ConsentLifetime { get; set; } - public int AbsoluteRefreshTokenLifetime { get; set; } + public int AbsoluteRefreshTokenLifetime { get; set; } - public int SlidingRefreshTokenLifetime { get; set; } + public int SlidingRefreshTokenLifetime { get; set; } - public int RefreshTokenUsage { get; set; } + public int RefreshTokenUsage { get; set; } - public bool UpdateAccessTokenClaimsOnRefresh { get; set; } + public bool UpdateAccessTokenClaimsOnRefresh { get; set; } - public int RefreshTokenExpiration { get; set; } + public int RefreshTokenExpiration { get; set; } - public int AccessTokenType { get; set; } + public int AccessTokenType { get; set; } - public bool EnableLocalLogin { get; set; } + public bool EnableLocalLogin { get; set; } - public bool IncludeJwtId { get; set; } + public bool IncludeJwtId { get; set; } - public bool AlwaysSendClientClaims { get; set; } + public bool AlwaysSendClientClaims { get; set; } - public string ClientClaimsPrefix { get; set; } + public string ClientClaimsPrefix { get; set; } - public string PairWiseSubjectSalt { get; set; } + public string PairWiseSubjectSalt { get; set; } - public int? UserSsoLifetime { get; set; } + public int? UserSsoLifetime { get; set; } - public string UserCodeType { get; set; } + public string UserCodeType { get; set; } - public int DeviceCodeLifetime { get; set; } - } -} \ No newline at end of file + public int DeviceCodeLifetime { get; set; } +} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientGrantTypeConsts.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientGrantTypeConsts.cs index 2407f83cc0..0a07ad38c2 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientGrantTypeConsts.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientGrantTypeConsts.cs @@ -1,7 +1,6 @@ -namespace Volo.Abp.IdentityServer.Clients +namespace Volo.Abp.IdentityServer.Clients; + +public class ClientGrantTypeConsts { - public class ClientGrantTypeConsts - { - public static int GrantTypeMaxLength { get; set; } = 250; - } + public static int GrantTypeMaxLength { get; set; } = 250; } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientIdPRestrictionConsts.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientIdPRestrictionConsts.cs index b238a01935..19d87ce50b 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientIdPRestrictionConsts.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientIdPRestrictionConsts.cs @@ -1,10 +1,9 @@ -namespace Volo.Abp.IdentityServer.Clients +namespace Volo.Abp.IdentityServer.Clients; + +public class ClientIdPRestrictionConsts { - public class ClientIdPRestrictionConsts - { - /// - /// Default value: 200 - /// - public static int ProviderMaxLength { get; set; } = 200; - } -} \ No newline at end of file + /// + /// Default value: 200 + /// + public static int ProviderMaxLength { get; set; } = 200; +} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUriConsts.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUriConsts.cs index 7d4764e1a3..43471a0757 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUriConsts.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUriConsts.cs @@ -1,11 +1,10 @@ -namespace Volo.Abp.IdentityServer.Clients +namespace Volo.Abp.IdentityServer.Clients; + +public class ClientPostLogoutRedirectUriConsts { - public class ClientPostLogoutRedirectUriConsts - { - /// - /// Default value: 200 - /// - public static int PostLogoutRedirectUriMaxLength { get; set; } = 2000; - public static int PostLogoutRedirectUriMaxLengthValue { get; set; } = 2000; - } -} \ No newline at end of file + /// + /// Default value: 200 + /// + public static int PostLogoutRedirectUriMaxLength { get; set; } = 2000; + public static int PostLogoutRedirectUriMaxLengthValue { get; set; } = 2000; +} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientPropertyConsts.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientPropertyConsts.cs index 664e1076b0..5be373dc7b 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientPropertyConsts.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientPropertyConsts.cs @@ -1,15 +1,14 @@ -namespace Volo.Abp.IdentityServer.Clients +namespace Volo.Abp.IdentityServer.Clients; + +public class ClientPropertyConsts { - public class ClientPropertyConsts - { - /// - /// Default value: 250 - /// - public static int KeyMaxLength { get; set; } = 250; - - /// - /// Default value: 2000 - /// - public static int ValueMaxLength { get; set; } = 2000; - } -} \ No newline at end of file + /// + /// Default value: 250 + /// + public static int KeyMaxLength { get; set; } = 250; + + /// + /// Default value: 2000 + /// + public static int ValueMaxLength { get; set; } = 2000; +} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientRedirectUriConsts.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientRedirectUriConsts.cs index 7650a3d952..ad8c31a2bf 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientRedirectUriConsts.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientRedirectUriConsts.cs @@ -1,11 +1,10 @@ -namespace Volo.Abp.IdentityServer.Clients +namespace Volo.Abp.IdentityServer.Clients; + +public class ClientRedirectUriConsts { - public class ClientRedirectUriConsts - { - /// - /// Default value: 2000 - /// - public static int RedirectUriMaxLength { get; set; } = 2000; - public static int RedirectUriMaxLengthValue { get; set; } = 2000; - } -} \ No newline at end of file + /// + /// Default value: 2000 + /// + public static int RedirectUriMaxLength { get; set; } = 2000; + public static int RedirectUriMaxLengthValue { get; set; } = 2000; +} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientScopeConsts.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientScopeConsts.cs index 0ec1c04595..38930ab3db 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientScopeConsts.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientScopeConsts.cs @@ -1,10 +1,9 @@ -namespace Volo.Abp.IdentityServer.Clients +namespace Volo.Abp.IdentityServer.Clients; + +public class ClientScopeConsts { - public class ClientScopeConsts - { - /// - /// Default value: 200 - /// - public static int ScopeMaxLength { get; set; } = 200; - } -} \ No newline at end of file + /// + /// Default value: 200 + /// + public static int ScopeMaxLength { get; set; } = 200; +} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientSecretConsts.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientSecretConsts.cs index 60eb0807d1..64364da622 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientSecretConsts.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientSecretConsts.cs @@ -1,20 +1,19 @@ -namespace Volo.Abp.IdentityServer.Clients +namespace Volo.Abp.IdentityServer.Clients; + +public class ClientSecretConsts { - public class ClientSecretConsts - { - /// - /// Default value: 250 - /// - public static int TypeMaxLength { get; set; } = 250; + /// + /// Default value: 250 + /// + public static int TypeMaxLength { get; set; } = 250; - /// - /// Default value: 4000 - /// - public static int ValueMaxLength { get; set; } = 4000; + /// + /// Default value: 4000 + /// + public static int ValueMaxLength { get; set; } = 4000; - /// - /// Default value: 2000 - /// - public static int DescriptionMaxLength { get; set; } = 2000; - } + /// + /// Default value: 2000 + /// + public static int DescriptionMaxLength { get; set; } = 2000; } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Devices/DeviceFlowCodesConsts.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Devices/DeviceFlowCodesConsts.cs index 80d82bbfa8..2c2c42474e 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Devices/DeviceFlowCodesConsts.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Devices/DeviceFlowCodesConsts.cs @@ -1,19 +1,18 @@ -namespace Volo.Abp.IdentityServer.Devices +namespace Volo.Abp.IdentityServer.Devices; + +public class DeviceFlowCodesConsts { - public class DeviceFlowCodesConsts - { - public static int DeviceCodeMaxLength { get; set; } = 200; + public static int DeviceCodeMaxLength { get; set; } = 200; - public static int UserCodeMaxLength { get; set; } = 200; + public static int UserCodeMaxLength { get; set; } = 200; - public static int SubjectIdMaxLength { get; set; } = 200; + public static int SubjectIdMaxLength { get; set; } = 200; - public static int SessionIdMaxLength { get; set; } = 100; + public static int SessionIdMaxLength { get; set; } = 100; - public static int DescriptionMaxLength { get; set; } = 200; + public static int DescriptionMaxLength { get; set; } = 200; - public static int ClientIdMaxLength { get; set; } = 200; + public static int ClientIdMaxLength { get; set; } = 200; - public static int DataMaxLength { get; set; } = 50000; - } + public static int DataMaxLength { get; set; } = 50000; } 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 66fa1f6eff..7f23101f58 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 @@ -1,26 +1,25 @@ using System; -namespace Volo.Abp.IdentityServer.Devices +namespace Volo.Abp.IdentityServer.Devices; + +[Serializable] +public class DeviceFlowCodesEto { - [Serializable] - public class DeviceFlowCodesEto - { - public Guid Id { get; set; } + public Guid Id { get; set; } - public string DeviceCode { get; set; } + public string DeviceCode { get; set; } - public string UserCode { get; set; } + public string UserCode { get; set; } - public string SubjectId { get; set; } + public string SubjectId { get; set; } - public string SessionId { get; set; } + public string SessionId { get; set; } - public string ClientId { get; set; } + public string ClientId { get; set; } - public string Description { get; set; } + public string Description { get; set; } - public DateTime? Expiration { get; set; } + public DateTime? Expiration { get; set; } - public string Data { get; set; } - } + public string Data { get; set; } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Grants/PersistedGrantConsts.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Grants/PersistedGrantConsts.cs index e0e753637a..1db567a5f1 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Grants/PersistedGrantConsts.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Grants/PersistedGrantConsts.cs @@ -1,45 +1,44 @@ -namespace Volo.Abp.IdentityServer.Grants +namespace Volo.Abp.IdentityServer.Grants; + +public class PersistedGrantConsts { - public class PersistedGrantConsts - { - /// - /// Default value: 200 - /// - public static int KeyMaxLength { get; set; } = 200; - - /// - /// Default value: 50 - /// - public static int TypeMaxLength { get; set; } = 50; - - /// - /// Default value: 200 - /// - public static int SubjectIdMaxLength { get; set; } = 200; - - /// - /// Default value: 100 - /// - public static int SessionIdMaxLength { get; set; } = 100; - - /// - /// Default value: 200 - /// - public static int ClientIdMaxLength { get; set; } = 200; - - /// - /// Default value: 200 - /// - public static int DescriptionMaxLength { get; set; } = 200; - - /// - /// Default value: 50000 - /// - public static int DataMaxLength { get; set; } = 50000; - - /// - /// Default value: 50000 - /// - public static int DataMaxLengthValue { get; set; } = 50000; - } + /// + /// Default value: 200 + /// + public static int KeyMaxLength { get; set; } = 200; + + /// + /// Default value: 50 + /// + public static int TypeMaxLength { get; set; } = 50; + + /// + /// Default value: 200 + /// + public static int SubjectIdMaxLength { get; set; } = 200; + + /// + /// Default value: 100 + /// + public static int SessionIdMaxLength { get; set; } = 100; + + /// + /// Default value: 200 + /// + public static int ClientIdMaxLength { get; set; } = 200; + + /// + /// Default value: 200 + /// + public static int DescriptionMaxLength { get; set; } = 200; + + /// + /// Default value: 50000 + /// + public static int DataMaxLength { get; set; } = 50000; + + /// + /// Default value: 50000 + /// + public static int DataMaxLengthValue { get; set; } = 50000; } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Grants/PersistedGrantEto.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Grants/PersistedGrantEto.cs index 9d5db878f7..9c2d42ec18 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Grants/PersistedGrantEto.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Grants/PersistedGrantEto.cs @@ -1,24 +1,23 @@ using System; -namespace Volo.Abp.IdentityServer.Grants +namespace Volo.Abp.IdentityServer.Grants; + +[Serializable] +public class PersistedGrantEto { - [Serializable] - public class PersistedGrantEto - { - public Guid Id { get; set; } + public Guid Id { get; set; } - public string Key { get; set; } + public string Key { get; set; } - public string Type { get; set; } + public string Type { get; set; } - public string SubjectId { get; set; } + public string SubjectId { get; set; } - public string ClientId { get; set; } + public string ClientId { get; set; } - public DateTime CreationTime { get; set; } + public DateTime CreationTime { get; set; } - public DateTime? Expiration { get; set; } + public DateTime? Expiration { get; set; } - public string Data { get; set; } - } -} \ No newline at end of file + public string Data { get; set; } +} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceConsts.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceConsts.cs index 66f8120b6a..ca33785f93 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceConsts.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceConsts.cs @@ -1,20 +1,19 @@ -namespace Volo.Abp.IdentityServer.IdentityResources +namespace Volo.Abp.IdentityServer.IdentityResources; + +public class IdentityResourceConsts { - public class IdentityResourceConsts - { - /// - /// Default value: 200 - /// - public static int NameMaxLength { get; set; } = 200; + /// + /// Default value: 200 + /// + public static int NameMaxLength { get; set; } = 200; - /// - /// Default value: 200 - /// - public static int DisplayNameMaxLength { get; set; } = 200; + /// + /// Default value: 200 + /// + public static int DisplayNameMaxLength { get; set; } = 200; - /// - /// Default value: 1000 - /// - public static int DescriptionMaxLength { get; set; } = 1000; - } + /// + /// Default value: 1000 + /// + public static int DescriptionMaxLength { get; set; } = 1000; } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceEto.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceEto.cs index c382642a9f..4742ed2aaf 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceEto.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceEto.cs @@ -1,24 +1,23 @@ using System; -namespace Volo.Abp.IdentityServer.IdentityResources +namespace Volo.Abp.IdentityServer.IdentityResources; + +[Serializable] +public class IdentityResourceEto { - [Serializable] - public class IdentityResourceEto - { - public Guid Id { get; set; } + public Guid Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } - public string DisplayName { get; set; } + public string DisplayName { get; set; } - public string Description { get; set; } + public string Description { get; set; } - public bool Enabled { get; set; } + public bool Enabled { get; set; } - public bool Required { get; set; } + public bool Required { get; set; } - public bool Emphasize { get; set; } + public bool Emphasize { get; set; } - public bool ShowInDiscoveryDocument { get; set; } - } -} \ No newline at end of file + public bool ShowInDiscoveryDocument { get; set; } +} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/IdentityResources/IdentityResourcePropertyConsts.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/IdentityResources/IdentityResourcePropertyConsts.cs index 98a5a93941..ff09f80d7e 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/IdentityResources/IdentityResourcePropertyConsts.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/IdentityResources/IdentityResourcePropertyConsts.cs @@ -1,9 +1,8 @@ -namespace Volo.Abp.IdentityServer.IdentityResources +namespace Volo.Abp.IdentityServer.IdentityResources; + +public class IdentityResourcePropertyConsts { - public class IdentityResourcePropertyConsts - { - public static int KeyMaxLength { get; set; } = 250; + public static int KeyMaxLength { get; set; } = 250; - public static int ValueMaxLength { get; set; } = 2000; - } + public static int ValueMaxLength { get; set; } = 2000; } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/IdentityServerSecurityLogActionConsts.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/IdentityServerSecurityLogActionConsts.cs index 47ad6b21d5..fe23413f8e 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/IdentityServerSecurityLogActionConsts.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/IdentityServerSecurityLogActionConsts.cs @@ -1,19 +1,18 @@ -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class IdentityServerSecurityLogActionConsts { - public class IdentityServerSecurityLogActionConsts - { - public static string LoginSucceeded { get; set; } = "LoginSucceeded"; + public static string LoginSucceeded { get; set; } = "LoginSucceeded"; - public static string LoginLockedout { get; set; } = "LoginLockedout"; + public static string LoginLockedout { get; set; } = "LoginLockedout"; - public static string LoginNotAllowed { get; set; } = "LoginNotAllowed"; + public static string LoginNotAllowed { get; set; } = "LoginNotAllowed"; - public static string LoginRequiresTwoFactor { get; set; } = "LoginRequiresTwoFactor"; + public static string LoginRequiresTwoFactor { get; set; } = "LoginRequiresTwoFactor"; - public static string LoginFailed { get; set; } = "LoginFailed"; + public static string LoginFailed { get; set; } = "LoginFailed"; - public static string LoginInvalidUserName { get; set; } = "LoginInvalidUserName"; + public static string LoginInvalidUserName { get; set; } = "LoginInvalidUserName"; - public static string LoginInvalidUserNameOrPassword { get; set; } = "LoginInvalidUserNameOrPassword"; - } + public static string LoginInvalidUserNameOrPassword { get; set; } = "LoginInvalidUserNameOrPassword"; } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/IdentityServerSecurityLogIdentityConsts.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/IdentityServerSecurityLogIdentityConsts.cs index 4a5f96e0e2..b5d83e3d41 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/IdentityServerSecurityLogIdentityConsts.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/IdentityServerSecurityLogIdentityConsts.cs @@ -1,7 +1,6 @@ -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class IdentityServerSecurityLogIdentityConsts { - public class IdentityServerSecurityLogIdentityConsts - { - public static string IdentityServer { get; set; } = "IdentityServer"; - } + public static string IdentityServer { get; set; } = "IdentityServer"; } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Localization/AbpIdentityServerResource.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Localization/AbpIdentityServerResource.cs index 1fc19461fc..5c585f1601 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Localization/AbpIdentityServerResource.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Localization/AbpIdentityServerResource.cs @@ -1,10 +1,9 @@ using Volo.Abp.Localization; -namespace Volo.Abp.IdentityServer.Localization +namespace Volo.Abp.IdentityServer.Localization; + +[LocalizationResourceName("AbpIdentityServer")] +public class AbpIdentityServerResource { - [LocalizationResourceName("AbpIdentityServer")] - public class AbpIdentityServerResource - { - } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/UserClaimConsts.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/UserClaimConsts.cs index cb0279fd2b..81cbb1b2fc 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/UserClaimConsts.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/UserClaimConsts.cs @@ -1,10 +1,9 @@ -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class UserClaimConsts { - public class UserClaimConsts - { - /// - /// Default value: 200 - /// - public static int TypeMaxLength { get; set; } = 200; - } -} \ No newline at end of file + /// + /// Default value: 200 + /// + public static int TypeMaxLength { get; set; } = 200; +} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/ObjectExtending/IdentityServerModuleExtensionConfiguration.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/ObjectExtending/IdentityServerModuleExtensionConfiguration.cs index fe89b7400a..c79bd35a5a 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/ObjectExtending/IdentityServerModuleExtensionConfiguration.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/ObjectExtending/IdentityServerModuleExtensionConfiguration.cs @@ -1,44 +1,43 @@ using System; using Volo.Abp.ObjectExtending.Modularity; -namespace Volo.Abp.ObjectExtending +namespace Volo.Abp.ObjectExtending; + +public class IdentityServerModuleExtensionConfiguration : ModuleExtensionConfiguration { - public class IdentityServerModuleExtensionConfiguration : ModuleExtensionConfiguration + public IdentityServerModuleExtensionConfiguration ConfigureClient( + Action configureAction) { - public IdentityServerModuleExtensionConfiguration ConfigureClient( - Action configureAction) - { - return this.ConfigureEntity( - IdentityServerModuleExtensionConsts.EntityNames.Client, - configureAction - ); - } + return this.ConfigureEntity( + IdentityServerModuleExtensionConsts.EntityNames.Client, + configureAction + ); + } - public IdentityServerModuleExtensionConfiguration ConfigureApiResource( - Action configureAction) - { - return this.ConfigureEntity( - IdentityServerModuleExtensionConsts.EntityNames.ApiResource, - configureAction - ); - } + public IdentityServerModuleExtensionConfiguration ConfigureApiResource( + Action configureAction) + { + return this.ConfigureEntity( + IdentityServerModuleExtensionConsts.EntityNames.ApiResource, + configureAction + ); + } - public IdentityServerModuleExtensionConfiguration ConfigureApiScope( - Action configureAction) - { - return this.ConfigureEntity( - IdentityServerModuleExtensionConsts.EntityNames.ApiScope, - configureAction - ); - } + public IdentityServerModuleExtensionConfiguration ConfigureApiScope( + Action configureAction) + { + return this.ConfigureEntity( + IdentityServerModuleExtensionConsts.EntityNames.ApiScope, + configureAction + ); + } - public IdentityServerModuleExtensionConfiguration ConfigureIdentityResource( - Action configureAction) - { - return this.ConfigureEntity( - IdentityServerModuleExtensionConsts.EntityNames.IdentityResource, - configureAction - ); - } + public IdentityServerModuleExtensionConfiguration ConfigureIdentityResource( + Action configureAction) + { + return this.ConfigureEntity( + IdentityServerModuleExtensionConsts.EntityNames.IdentityResource, + configureAction + ); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/ObjectExtending/IdentityServerModuleExtensionConfigurationDictionaryExtensions.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/ObjectExtending/IdentityServerModuleExtensionConfigurationDictionaryExtensions.cs index a943ca1839..146ebb324c 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/ObjectExtending/IdentityServerModuleExtensionConfigurationDictionaryExtensions.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/ObjectExtending/IdentityServerModuleExtensionConfigurationDictionaryExtensions.cs @@ -1,18 +1,17 @@ using System; using Volo.Abp.ObjectExtending.Modularity; -namespace Volo.Abp.ObjectExtending +namespace Volo.Abp.ObjectExtending; + +public static class IdentityServerModuleExtensionConfigurationDictionaryExtensions { - public static class IdentityServerModuleExtensionConfigurationDictionaryExtensions + public static ModuleExtensionConfigurationDictionary ConfigureIdentityServer( + this ModuleExtensionConfigurationDictionary modules, + Action configureAction) { - public static ModuleExtensionConfigurationDictionary ConfigureIdentityServer( - this ModuleExtensionConfigurationDictionary modules, - Action configureAction) - { - return modules.ConfigureModule( - IdentityServerModuleExtensionConsts.ModuleName, - configureAction - ); - } + return modules.ConfigureModule( + IdentityServerModuleExtensionConsts.ModuleName, + configureAction + ); } -} \ No newline at end of file +} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/ObjectExtending/IdentityServerModuleExtensionConsts.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/ObjectExtending/IdentityServerModuleExtensionConsts.cs index a9396ff95a..0ffe5e757e 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/ObjectExtending/IdentityServerModuleExtensionConsts.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/ObjectExtending/IdentityServerModuleExtensionConsts.cs @@ -1,18 +1,17 @@ -namespace Volo.Abp.ObjectExtending +namespace Volo.Abp.ObjectExtending; + +public static class IdentityServerModuleExtensionConsts { - public static class IdentityServerModuleExtensionConsts - { - public const string ModuleName = "IdentityServer"; + public const string ModuleName = "IdentityServer"; - public static class EntityNames - { - public const string Client = "Client"; + public static class EntityNames + { + public const string Client = "Client"; - public const string IdentityResource = "IdentityResource"; + public const string IdentityResource = "IdentityResource"; - public const string ApiResource = "ApiResource"; + public const string ApiResource = "ApiResource"; - public const string ApiScope = "ApiScope"; - } + public const string ApiScope = "ApiScope"; } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpClaimsService.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpClaimsService.cs index a977afd2e9..57ee725046 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpClaimsService.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpClaimsService.cs @@ -7,14 +7,14 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Volo.Abp.Security.Claims; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class AbpClaimsService : DefaultClaimsService { - public class AbpClaimsService : DefaultClaimsService - { - protected readonly AbpClaimsServiceOptions Options; + protected readonly AbpClaimsServiceOptions Options; - private static readonly string[] AdditionalOptionalClaimNames = - { + private static readonly string[] AdditionalOptionalClaimNames = + { AbpClaimTypes.TenantId, AbpClaimTypes.ImpersonatorTenantId, AbpClaimTypes.ImpersonatorUserId, @@ -25,36 +25,35 @@ namespace Volo.Abp.IdentityServer JwtClaimTypes.FamilyName, }; - public AbpClaimsService( - IProfileService profile, - ILogger logger, - IOptions options) - : base(profile, logger) - { - Options = options.Value; - } + public AbpClaimsService( + IProfileService profile, + ILogger logger, + IOptions options) + : base(profile, logger) + { + Options = options.Value; + } - protected override IEnumerable FilterRequestedClaimTypes(IEnumerable claimTypes) - { - return base.FilterRequestedClaimTypes(claimTypes) - .Union(Options.RequestedClaims); - } + protected override IEnumerable FilterRequestedClaimTypes(IEnumerable claimTypes) + { + return base.FilterRequestedClaimTypes(claimTypes) + .Union(Options.RequestedClaims); + } - protected override IEnumerable GetOptionalClaims(ClaimsPrincipal subject) - { - return base.GetOptionalClaims(subject) - .Union(GetAdditionalOptionalClaims(subject)); - } + protected override IEnumerable GetOptionalClaims(ClaimsPrincipal subject) + { + return base.GetOptionalClaims(subject) + .Union(GetAdditionalOptionalClaims(subject)); + } - protected virtual IEnumerable GetAdditionalOptionalClaims(ClaimsPrincipal subject) + protected virtual IEnumerable GetAdditionalOptionalClaims(ClaimsPrincipal subject) + { + foreach (var claimName in AdditionalOptionalClaimNames) { - foreach (var claimName in AdditionalOptionalClaimNames) + var claim = subject.FindFirst(claimName); + if (claim != null) { - var claim = subject.FindFirst(claimName); - if (claim != null) - { - yield return claim; - } + yield return claim; } } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpClaimsServiceOptions.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpClaimsServiceOptions.cs index a940cb6119..dee193b4dd 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpClaimsServiceOptions.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpClaimsServiceOptions.cs @@ -1,14 +1,13 @@ using System.Collections.Generic; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class AbpClaimsServiceOptions { - public class AbpClaimsServiceOptions - { - public List RequestedClaims { get; } + public List RequestedClaims { get; } - public AbpClaimsServiceOptions() - { - RequestedClaims = new List(); - } + public AbpClaimsServiceOptions() + { + RequestedClaims = new List(); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpClientConfigurationValidator.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpClientConfigurationValidator.cs index 508cc03db4..fef38b9325 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpClientConfigurationValidator.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpClientConfigurationValidator.cs @@ -4,22 +4,21 @@ using System.Threading.Tasks; using IdentityServer4.Configuration; using IdentityServer4.Validation; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class AbpClientConfigurationValidator : DefaultClientConfigurationValidator { - public class AbpClientConfigurationValidator : DefaultClientConfigurationValidator + public AbpClientConfigurationValidator(IdentityServerOptions options) + : base(options) { - public AbpClientConfigurationValidator(IdentityServerOptions options) - : base(options) - { - } + } - protected override Task ValidateAllowedCorsOriginsAsync(ClientConfigurationValidationContext context) - { - context.Client.AllowedCorsOrigins = context.Client - .AllowedCorsOrigins.Select(x => x.Replace("{0}.", string.Empty, StringComparison.OrdinalIgnoreCase)) - .ToHashSet(); + protected override Task ValidateAllowedCorsOriginsAsync(ClientConfigurationValidationContext context) + { + context.Client.AllowedCorsOrigins = context.Client + .AllowedCorsOrigins.Select(x => x.Replace("{0}.", string.Empty, StringComparison.OrdinalIgnoreCase)) + .ToHashSet(); - return base.ValidateAllowedCorsOriginsAsync(context); - } + return base.ValidateAllowedCorsOriginsAsync(context); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpCorsPolicyService.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpCorsPolicyService.cs index c1932d0435..ac6c9d9edf 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpCorsPolicyService.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpCorsPolicyService.cs @@ -12,61 +12,60 @@ using Volo.Abp.Caching; using Volo.Abp.DependencyInjection; using Volo.Abp.IdentityServer.Clients; -namespace Volo.Abp.IdentityServer -{ - public class AbpCorsPolicyService : ICorsPolicyService - { - public ILogger Logger { get; set; } - protected IHybridServiceScopeFactory HybridServiceScopeFactory { get; } - protected IDistributedCache Cache { get; } - protected IdentityServerOptions Options { get; } - - public AbpCorsPolicyService( - IDistributedCache cache, - IHybridServiceScopeFactory hybridServiceScopeFactory, - IOptions options) - { - Cache = cache; - HybridServiceScopeFactory = hybridServiceScopeFactory; - Options = options.Value; - Logger = NullLogger.Instance; - } +namespace Volo.Abp.IdentityServer; - public virtual async Task IsOriginAllowedAsync(string origin) - { - var cacheItem = await Cache.GetOrAddAsync(AllowedCorsOriginsCacheItem.AllOrigins, CreateCacheItemAsync, - () => new DistributedCacheEntryOptions() - { - AbsoluteExpirationRelativeToNow = Options.Caching.CorsExpiration - }); +public class AbpCorsPolicyService : ICorsPolicyService +{ + public ILogger Logger { get; set; } + protected IHybridServiceScopeFactory HybridServiceScopeFactory { get; } + protected IDistributedCache Cache { get; } + protected IdentityServerOptions Options { get; } - var isAllowed = await IsOriginAllowedAsync(cacheItem.AllowedOrigins, origin); + public AbpCorsPolicyService( + IDistributedCache cache, + IHybridServiceScopeFactory hybridServiceScopeFactory, + IOptions options) + { + Cache = cache; + HybridServiceScopeFactory = hybridServiceScopeFactory; + Options = options.Value; + Logger = NullLogger.Instance; + } - if (!isAllowed) + public virtual async Task IsOriginAllowedAsync(string origin) + { + var cacheItem = await Cache.GetOrAddAsync(AllowedCorsOriginsCacheItem.AllOrigins, CreateCacheItemAsync, + () => new DistributedCacheEntryOptions() { - Logger.LogWarning($"Origin is not allowed: {origin}"); - } + AbsoluteExpirationRelativeToNow = Options.Caching.CorsExpiration + }); - return isAllowed; - } + var isAllowed = await IsOriginAllowedAsync(cacheItem.AllowedOrigins, origin); - protected virtual async Task CreateCacheItemAsync() + if (!isAllowed) { - // doing this here and not in the ctor because: https://github.com/aspnet/AspNetCore/issues/2377 - using (var scope = HybridServiceScopeFactory.CreateScope()) - { - var clientRepository = scope.ServiceProvider.GetRequiredService(); - - return new AllowedCorsOriginsCacheItem - { - AllowedOrigins = (await clientRepository.GetAllDistinctAllowedCorsOriginsAsync()).ToArray() - }; - } + Logger.LogWarning($"Origin is not allowed: {origin}"); } - protected virtual Task IsOriginAllowedAsync(string[] allowedOrigins, string origin) + return isAllowed; + } + + protected virtual async Task CreateCacheItemAsync() + { + // doing this here and not in the ctor because: https://github.com/aspnet/AspNetCore/issues/2377 + using (var scope = HybridServiceScopeFactory.CreateScope()) { - return Task.FromResult(allowedOrigins.Contains(origin, StringComparer.OrdinalIgnoreCase)); + var clientRepository = scope.ServiceProvider.GetRequiredService(); + + return new AllowedCorsOriginsCacheItem + { + AllowedOrigins = (await clientRepository.GetAllDistinctAllowedCorsOriginsAsync()).ToArray() + }; } } + + protected virtual Task IsOriginAllowedAsync(string[] allowedOrigins, string origin) + { + return Task.FromResult(allowedOrigins.Contains(origin, StringComparer.OrdinalIgnoreCase)); + } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerBuilderExtensions.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerBuilderExtensions.cs index d144208c02..10d1b2972d 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerBuilderExtensions.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerBuilderExtensions.cs @@ -17,100 +17,100 @@ using Volo.Abp.IdentityServer.AspNetIdentity; using Volo.Abp.Security.Claims; using IdentityUser = Volo.Abp.Identity.IdentityUser; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public static class AbpIdentityServerBuilderExtensions { - public static class AbpIdentityServerBuilderExtensions + public static IIdentityServerBuilder AddAbpIdentityServer( + this IIdentityServerBuilder builder, + AbpIdentityServerBuilderOptions options = null) { - public static IIdentityServerBuilder AddAbpIdentityServer( - this IIdentityServerBuilder builder, - AbpIdentityServerBuilderOptions options = null) + if (options == null) { - if (options == null) - { - options = new AbpIdentityServerBuilderOptions(); - } + options = new AbpIdentityServerBuilderOptions(); + } - //TODO: AspNet Identity integration lines. Can be extracted to a extension method - if (options.IntegrateToAspNetIdentity) - { - builder.AddAspNetIdentity(); - builder.AddProfileService(); - builder.AddResourceOwnerValidator(); + //TODO: AspNet Identity integration lines. Can be extracted to a extension method + if (options.IntegrateToAspNetIdentity) + { + builder.AddAspNetIdentity(); + builder.AddProfileService(); + builder.AddResourceOwnerValidator(); - builder.Services.Remove(builder.Services.LastOrDefault(x => x.ServiceType == typeof(IUserClaimsPrincipalFactory))); - builder.Services.AddTransient, AbpUserClaimsFactory>(); - builder.Services.AddTransient>, ObjectAccessor>(); - } + builder.Services.Remove(builder.Services.LastOrDefault(x => x.ServiceType == typeof(IUserClaimsPrincipalFactory))); + builder.Services.AddTransient, AbpUserClaimsFactory>(); + builder.Services.AddTransient>, ObjectAccessor>(); + } - builder.Services.Replace(ServiceDescriptor.Transient()); + builder.Services.Replace(ServiceDescriptor.Transient()); - if (options.UpdateAbpClaimTypes) - { - AbpClaimTypes.UserId = JwtClaimTypes.Subject; - AbpClaimTypes.UserName = JwtClaimTypes.Name; - AbpClaimTypes.Role = JwtClaimTypes.Role; - AbpClaimTypes.Email = JwtClaimTypes.Email; - } + if (options.UpdateAbpClaimTypes) + { + AbpClaimTypes.UserId = JwtClaimTypes.Subject; + AbpClaimTypes.UserName = JwtClaimTypes.Name; + AbpClaimTypes.Role = JwtClaimTypes.Role; + AbpClaimTypes.Email = JwtClaimTypes.Email; + } - if (options.UpdateJwtSecurityTokenHandlerDefaultInboundClaimTypeMap) - { - JwtSecurityTokenHandler.DefaultInboundClaimTypeMap[AbpClaimTypes.UserId] = AbpClaimTypes.UserId; - JwtSecurityTokenHandler.DefaultInboundClaimTypeMap[AbpClaimTypes.UserName] = AbpClaimTypes.UserName; - JwtSecurityTokenHandler.DefaultInboundClaimTypeMap[AbpClaimTypes.Role] = AbpClaimTypes.Role; - JwtSecurityTokenHandler.DefaultInboundClaimTypeMap[AbpClaimTypes.Email] = AbpClaimTypes.Email; - } + if (options.UpdateJwtSecurityTokenHandlerDefaultInboundClaimTypeMap) + { + JwtSecurityTokenHandler.DefaultInboundClaimTypeMap[AbpClaimTypes.UserId] = AbpClaimTypes.UserId; + JwtSecurityTokenHandler.DefaultInboundClaimTypeMap[AbpClaimTypes.UserName] = AbpClaimTypes.UserName; + JwtSecurityTokenHandler.DefaultInboundClaimTypeMap[AbpClaimTypes.Role] = AbpClaimTypes.Role; + JwtSecurityTokenHandler.DefaultInboundClaimTypeMap[AbpClaimTypes.Email] = AbpClaimTypes.Email; + } + + return builder; + } - return builder; + //TODO: Use the latest Identity server code to optimize performance. + // https://github.com/IdentityServer/IdentityServer4/blob/main/src/IdentityServer4/src/Configuration/DependencyInjection/BuilderExtensions/Crypto.cs + private static IIdentityServerBuilder AddAbpDeveloperSigningCredential( + this IIdentityServerBuilder builder, + bool persistKey = true, + string filename = null, + IdentityServerConstants.RsaSigningAlgorithm signingAlgorithm = IdentityServerConstants.RsaSigningAlgorithm.RS256) + { + if (filename == null) + { + filename = Path.Combine(Directory.GetCurrentDirectory(), "tempkey.rsa"); } - //TODO: Use the latest Identity server code to optimize performance. - // https://github.com/IdentityServer/IdentityServer4/blob/main/src/IdentityServer4/src/Configuration/DependencyInjection/BuilderExtensions/Crypto.cs - private static IIdentityServerBuilder AddAbpDeveloperSigningCredential( - this IIdentityServerBuilder builder, - bool persistKey = true, - string filename = null, - IdentityServerConstants.RsaSigningAlgorithm signingAlgorithm = IdentityServerConstants.RsaSigningAlgorithm.RS256) + if (File.Exists(filename)) { - if (filename == null) - { - filename = Path.Combine(Directory.GetCurrentDirectory(), "tempkey.rsa"); - } + var keyFile = File.ReadAllText(filename); + + var json = JObject.Parse(keyFile); + var keyId = json.GetValue("KeyId").Value(); + var jsonParameters = json.GetValue("Parameters"); + RSAParameters rsaParameters; + rsaParameters.D = Convert.FromBase64String(jsonParameters["D"].Value()); + rsaParameters.DP = Convert.FromBase64String(jsonParameters["DP"].Value()); + rsaParameters.DQ = Convert.FromBase64String(jsonParameters["DQ"].Value()); + rsaParameters.Exponent = Convert.FromBase64String(jsonParameters["Exponent"].Value()); + rsaParameters.InverseQ = Convert.FromBase64String(jsonParameters["InverseQ"].Value()); + rsaParameters.Modulus = Convert.FromBase64String(jsonParameters["Modulus"].Value()); + rsaParameters.P = Convert.FromBase64String(jsonParameters["P"].Value()); + rsaParameters.Q = Convert.FromBase64String(jsonParameters["Q"].Value()); + + return builder.AddSigningCredential(CryptoHelper.CreateRsaSecurityKey(rsaParameters, keyId), signingAlgorithm); + } + else + { + var key = CryptoHelper.CreateRsaSecurityKey(); - if (File.Exists(filename)) + RSAParameters parameters; + + if (key.Rsa != null) { - var keyFile = File.ReadAllText(filename); - - var json = JObject.Parse(keyFile); - var keyId = json.GetValue("KeyId").Value(); - var jsonParameters = json.GetValue("Parameters"); - RSAParameters rsaParameters; - rsaParameters.D = Convert.FromBase64String(jsonParameters["D"].Value()); - rsaParameters.DP = Convert.FromBase64String(jsonParameters["DP"].Value()); - rsaParameters.DQ = Convert.FromBase64String(jsonParameters["DQ"].Value()); - rsaParameters.Exponent = Convert.FromBase64String(jsonParameters["Exponent"].Value()); - rsaParameters.InverseQ = Convert.FromBase64String(jsonParameters["InverseQ"].Value()); - rsaParameters.Modulus = Convert.FromBase64String(jsonParameters["Modulus"].Value()); - rsaParameters.P = Convert.FromBase64String(jsonParameters["P"].Value()); - rsaParameters.Q = Convert.FromBase64String(jsonParameters["Q"].Value()); - - return builder.AddSigningCredential(CryptoHelper.CreateRsaSecurityKey(rsaParameters, keyId), signingAlgorithm); + parameters = key.Rsa.ExportParameters(includePrivateParameters: true); } else { - var key = CryptoHelper.CreateRsaSecurityKey(); - - RSAParameters parameters; - - if (key.Rsa != null) - { - parameters = key.Rsa.ExportParameters(includePrivateParameters: true); - } - else - { - parameters = key.Parameters; - } + parameters = key.Parameters; + } - var jObject = new JObject + var jObject = new JObject { { "KeyId", key.KeyId @@ -130,12 +130,11 @@ namespace Volo.Abp.IdentityServer } }; - if (persistKey) - { - File.WriteAllText(filename, jObject.ToString()); - } - return builder.AddSigningCredential(key, signingAlgorithm); + if (persistKey) + { + File.WriteAllText(filename, jObject.ToString()); } + return builder.AddSigningCredential(key, signingAlgorithm); } } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerBuilderOptions.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerBuilderOptions.cs index be76a5c008..1927c21746 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerBuilderOptions.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerBuilderOptions.cs @@ -1,31 +1,30 @@ using System.IdentityModel.Tokens.Jwt; using Volo.Abp.Security.Claims; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class AbpIdentityServerBuilderOptions { - public class AbpIdentityServerBuilderOptions - { - /// - /// Updates to be compatible with identity server claims. - /// Default: true. - /// - public bool UpdateJwtSecurityTokenHandlerDefaultInboundClaimTypeMap { get; set; } = true; + /// + /// Updates to be compatible with identity server claims. + /// Default: true. + /// + public bool UpdateJwtSecurityTokenHandlerDefaultInboundClaimTypeMap { get; set; } = true; - /// - /// Updates to be compatible with identity server claims. - /// Default: true. - /// - public bool UpdateAbpClaimTypes { get; set; } = true; + /// + /// Updates to be compatible with identity server claims. + /// Default: true. + /// + public bool UpdateAbpClaimTypes { get; set; } = true; - /// - /// Integrate to AspNet Identity. - /// Default: true. - /// - public bool IntegrateToAspNetIdentity { get; set; } = true; + /// + /// Integrate to AspNet Identity. + /// Default: true. + /// + public bool IntegrateToAspNetIdentity { get; set; } = true; - /// - /// Set false to suppress AddDeveloperSigningCredential() call on the IIdentityServerBuilder. - /// - public bool AddDeveloperSigningCredential { get; set; } = true; - } -} \ No newline at end of file + /// + /// Set false to suppress AddDeveloperSigningCredential() call on the IIdentityServerBuilder. + /// + public bool AddDeveloperSigningCredential { get; set; } = true; +} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerDbProperties.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerDbProperties.cs index 3e6fe6a986..836c26ec65 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerDbProperties.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerDbProperties.cs @@ -1,11 +1,10 @@ -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public static class AbpIdentityServerDbProperties { - public static class AbpIdentityServerDbProperties - { - public static string DbTablePrefix { get; set; } = "IdentityServer"; + public static string DbTablePrefix { get; set; } = "IdentityServer"; - public static string DbSchema { get; set; } = null; + public static string DbSchema { get; set; } = null; - public const string ConnectionStringName = "AbpIdentityServer"; - } + public const string ConnectionStringName = "AbpIdentityServer"; } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerDomainModule.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerDomainModule.cs index f75f10d687..d3663277cb 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerDomainModule.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerDomainModule.cs @@ -22,129 +22,128 @@ using Volo.Abp.Security.Claims; using Volo.Abp.Validation; using Volo.Abp.Threading; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +[DependsOn( + typeof(AbpIdentityServerDomainSharedModule), + typeof(AbpAutoMapperModule), + typeof(AbpIdentityDomainModule), + typeof(AbpSecurityModule), + typeof(AbpCachingModule), + typeof(AbpValidationModule), + typeof(AbpBackgroundWorkersModule) + )] +public class AbpIdentityServerDomainModule : AbpModule { - [DependsOn( - typeof(AbpIdentityServerDomainSharedModule), - typeof(AbpAutoMapperModule), - typeof(AbpIdentityDomainModule), - typeof(AbpSecurityModule), - typeof(AbpCachingModule), - typeof(AbpValidationModule), - typeof(AbpBackgroundWorkersModule) - )] - public class AbpIdentityServerDomainModule : AbpModule + private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner(); + + public override void ConfigureServices(ServiceConfigurationContext context) { - private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner(); + context.Services.AddAutoMapperObjectMapper(); - public override void ConfigureServices(ServiceConfigurationContext context) + Configure(options => { - context.Services.AddAutoMapperObjectMapper(); - - Configure(options => - { - options.AddProfile(validate: true); - }); + options.AddProfile(validate: true); + }); - Configure(options => - { - options.EtoMappings.Add(typeof(AbpIdentityServerDomainModule)); - options.EtoMappings.Add(typeof(AbpIdentityServerDomainModule)); - options.EtoMappings.Add(typeof(AbpIdentityServerDomainModule)); - options.EtoMappings.Add(typeof(AbpIdentityServerDomainModule)); - }); + Configure(options => + { + options.EtoMappings.Add(typeof(AbpIdentityServerDomainModule)); + options.EtoMappings.Add(typeof(AbpIdentityServerDomainModule)); + options.EtoMappings.Add(typeof(AbpIdentityServerDomainModule)); + options.EtoMappings.Add(typeof(AbpIdentityServerDomainModule)); + }); - Configure(options => - { - options.RequestedClaims.AddRange(new []{ + Configure(options => + { + options.RequestedClaims.AddRange(new[]{ AbpClaimTypes.TenantId, AbpClaimTypes.EditionId - }); - }); - - AddIdentityServer(context.Services); - } - - private static void AddIdentityServer(IServiceCollection services) - { - var configuration = services.GetConfiguration(); - var builderOptions = services.ExecutePreConfiguredActions(); - - var identityServerBuilder = services.AddIdentityServer(options => - { - options.Events.RaiseErrorEvents = true; - options.Events.RaiseInformationEvents = true; - options.Events.RaiseFailureEvents = true; - options.Events.RaiseSuccessEvents = true; }); + }); - if (builderOptions.AddDeveloperSigningCredential) - { - identityServerBuilder = identityServerBuilder.AddDeveloperSigningCredential(); - } + AddIdentityServer(context.Services); + } - identityServerBuilder.AddAbpIdentityServer(builderOptions); + private static void AddIdentityServer(IServiceCollection services) + { + var configuration = services.GetConfiguration(); + var builderOptions = services.ExecutePreConfiguredActions(); - services.ExecutePreConfiguredActions(identityServerBuilder); + var identityServerBuilder = services.AddIdentityServer(options => + { + options.Events.RaiseErrorEvents = true; + options.Events.RaiseInformationEvents = true; + options.Events.RaiseFailureEvents = true; + options.Events.RaiseSuccessEvents = true; + }); - if (!services.IsAdded()) - { - services.TryAddSingleton(); - } + if (builderOptions.AddDeveloperSigningCredential) + { + identityServerBuilder = identityServerBuilder.AddDeveloperSigningCredential(); + } - if (!services.IsAdded()) - { - services.TryAddSingleton(); - } + identityServerBuilder.AddAbpIdentityServer(builderOptions); - if (!services.IsAdded()) - { - identityServerBuilder.AddInMemoryClients(configuration.GetSection("IdentityServer:Clients")); - } + services.ExecutePreConfiguredActions(identityServerBuilder); - if (!services.IsAdded()) - { - identityServerBuilder.AddInMemoryApiResources(configuration.GetSection("IdentityServer:ApiResources")); - identityServerBuilder.AddInMemoryIdentityResources(configuration.GetSection("IdentityServer:IdentityResources")); - } + if (!services.IsAdded()) + { + services.TryAddSingleton(); } - public override void PostConfigureServices(ServiceConfigurationContext context) + if (!services.IsAdded()) { - OneTimeRunner.Run(() => - { - ModuleExtensionConfigurationHelper.ApplyEntityConfigurationToEntity( - IdentityServerModuleExtensionConsts.ModuleName, - IdentityServerModuleExtensionConsts.EntityNames.Client, - typeof(Client) - ); + services.TryAddSingleton(); + } - ModuleExtensionConfigurationHelper.ApplyEntityConfigurationToEntity( - IdentityServerModuleExtensionConsts.ModuleName, - IdentityServerModuleExtensionConsts.EntityNames.IdentityResource, - typeof(IdentityResource) - ); + if (!services.IsAdded()) + { + identityServerBuilder.AddInMemoryClients(configuration.GetSection("IdentityServer:Clients")); + } - ModuleExtensionConfigurationHelper.ApplyEntityConfigurationToEntity( - IdentityServerModuleExtensionConsts.ModuleName, - IdentityServerModuleExtensionConsts.EntityNames.ApiResource, - typeof(ApiResource) - ); - }); + if (!services.IsAdded()) + { + identityServerBuilder.AddInMemoryApiResources(configuration.GetSection("IdentityServer:ApiResources")); + identityServerBuilder.AddInMemoryIdentityResources(configuration.GetSection("IdentityServer:IdentityResources")); } + } + + public override void PostConfigureServices(ServiceConfigurationContext context) + { + OneTimeRunner.Run(() => + { + ModuleExtensionConfigurationHelper.ApplyEntityConfigurationToEntity( + IdentityServerModuleExtensionConsts.ModuleName, + IdentityServerModuleExtensionConsts.EntityNames.Client, + typeof(Client) + ); + + ModuleExtensionConfigurationHelper.ApplyEntityConfigurationToEntity( + IdentityServerModuleExtensionConsts.ModuleName, + IdentityServerModuleExtensionConsts.EntityNames.IdentityResource, + typeof(IdentityResource) + ); + + ModuleExtensionConfigurationHelper.ApplyEntityConfigurationToEntity( + IdentityServerModuleExtensionConsts.ModuleName, + IdentityServerModuleExtensionConsts.EntityNames.ApiResource, + typeof(ApiResource) + ); + }); + } - public override void OnApplicationInitialization(ApplicationInitializationContext context) + public override void OnApplicationInitialization(ApplicationInitializationContext context) + { + var options = context.ServiceProvider.GetRequiredService>().Value; + if (options.IsCleanupEnabled) { - var options = context.ServiceProvider.GetRequiredService>().Value; - if (options.IsCleanupEnabled) - { - context.ServiceProvider - .GetRequiredService() - .Add( - context.ServiceProvider - .GetRequiredService() - ); - } + context.ServiceProvider + .GetRequiredService() + .Add( + context.ServiceProvider + .GetRequiredService() + ); } } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerServiceCollectionExtensions.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerServiceCollectionExtensions.cs index baa04a6e5f..9e00511121 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerServiceCollectionExtensions.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerServiceCollectionExtensions.cs @@ -3,23 +3,22 @@ using IdentityServer4.Validation; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public static class AbpIdentityServerServiceCollectionExtensions { - public static class AbpIdentityServerServiceCollectionExtensions + public static void AddAbpStrictRedirectUriValidator(this IServiceCollection services) { - public static void AddAbpStrictRedirectUriValidator(this IServiceCollection services) - { - services.Replace(ServiceDescriptor.Transient()); - } + services.Replace(ServiceDescriptor.Transient()); + } - public static void AddAbpClientConfigurationValidator(this IServiceCollection services) - { - services.Replace(ServiceDescriptor.Transient()); - } + public static void AddAbpClientConfigurationValidator(this IServiceCollection services) + { + services.Replace(ServiceDescriptor.Transient()); + } - public static void AddAbpWildcardSubdomainCorsPolicyService(this IServiceCollection services) - { - services.Replace(ServiceDescriptor.Transient()); - } + public static void AddAbpWildcardSubdomainCorsPolicyService(this IServiceCollection services) + { + services.Replace(ServiceDescriptor.Transient()); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpStrictRedirectUriValidator.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpStrictRedirectUriValidator.cs index a4459d99e2..b3914bcd57 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpStrictRedirectUriValidator.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpStrictRedirectUriValidator.cs @@ -6,46 +6,45 @@ using IdentityServer4.Models; using IdentityServer4.Validation; using Volo.Abp.Text.Formatting; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class AbpStrictRedirectUriValidator : StrictRedirectUriValidator { - public class AbpStrictRedirectUriValidator : StrictRedirectUriValidator + public override async Task IsRedirectUriValidAsync(string requestedUri, Client client) { - public override async Task IsRedirectUriValidAsync(string requestedUri, Client client) - { - var isAllowed = await base.IsRedirectUriValidAsync(requestedUri, client); - return isAllowed || await IsRedirectUriValidWithDomainFormatsAsync(client.RedirectUris, requestedUri); - } + var isAllowed = await base.IsRedirectUriValidAsync(requestedUri, client); + return isAllowed || await IsRedirectUriValidWithDomainFormatsAsync(client.RedirectUris, requestedUri); + } + + public override async Task IsPostLogoutRedirectUriValidAsync(string requestedUri, Client client) + { + var isAllowed = await base.IsPostLogoutRedirectUriValidAsync(requestedUri, client); + return isAllowed || await IsRedirectUriValidWithDomainFormatsAsync(client.PostLogoutRedirectUris, requestedUri); + } - public override async Task IsPostLogoutRedirectUriValidAsync(string requestedUri, Client client) + protected virtual Task IsRedirectUriValidWithDomainFormatsAsync(IEnumerable uris, string requestedUri) + { + if (uris == null) { - var isAllowed = await base.IsPostLogoutRedirectUriValidAsync(requestedUri, client); - return isAllowed || await IsRedirectUriValidWithDomainFormatsAsync(client.PostLogoutRedirectUris, requestedUri); + return Task.FromResult(false); } - protected virtual Task IsRedirectUriValidWithDomainFormatsAsync(IEnumerable uris, string requestedUri) + foreach (var url in uris) { - if (uris == null) + var extractResult = FormattedStringValueExtracter.Extract(requestedUri, url, ignoreCase: true); + if (extractResult.IsMatch) { - return Task.FromResult(false); + return Task.FromResult(extractResult.Matches + .Aggregate(url, (current, nameValue) => current.Replace($"{{{nameValue.Name}}}", nameValue.Value)) + .Contains(requestedUri, StringComparison.OrdinalIgnoreCase)); } - foreach (var url in uris) + if (url.Replace("{0}.", "").Contains(requestedUri, StringComparison.OrdinalIgnoreCase)) { - var extractResult = FormattedStringValueExtracter.Extract(requestedUri, url, ignoreCase: true); - if (extractResult.IsMatch) - { - return Task.FromResult(extractResult.Matches - .Aggregate(url, (current, nameValue) => current.Replace($"{{{nameValue.Name}}}", nameValue.Value)) - .Contains(requestedUri, StringComparison.OrdinalIgnoreCase)); - } - - if (url.Replace("{0}.", "").Contains(requestedUri, StringComparison.OrdinalIgnoreCase)) - { - return Task.FromResult(true); - } + return Task.FromResult(true); } - - return Task.FromResult(false); } + + return Task.FromResult(false); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpWildcardSubdomainCorsPolicyService.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpWildcardSubdomainCorsPolicyService.cs index daf8d1f6f2..82658ceccd 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpWildcardSubdomainCorsPolicyService.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpWildcardSubdomainCorsPolicyService.cs @@ -7,43 +7,42 @@ using Volo.Abp.Caching; using Volo.Abp.DependencyInjection; using Volo.Abp.Text.Formatting; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class AbpWildcardSubdomainCorsPolicyService : AbpCorsPolicyService { - public class AbpWildcardSubdomainCorsPolicyService : AbpCorsPolicyService + public AbpWildcardSubdomainCorsPolicyService( + IDistributedCache cache, + IHybridServiceScopeFactory hybridServiceScopeFactory, + IOptions options) + : base(cache, hybridServiceScopeFactory, options) { - public AbpWildcardSubdomainCorsPolicyService( - IDistributedCache cache, - IHybridServiceScopeFactory hybridServiceScopeFactory, - IOptions options) - : base(cache, hybridServiceScopeFactory, options) - { + } + + protected override async Task IsOriginAllowedAsync(string[] allowedOrigins, string origin) + { + var isAllowed = await base.IsOriginAllowedAsync(allowedOrigins, origin); + if (isAllowed) + { + return true; } - protected override async Task IsOriginAllowedAsync(string[] allowedOrigins, string origin) + foreach (var url in allowedOrigins) { - var isAllowed = await base.IsOriginAllowedAsync(allowedOrigins, origin); - if (isAllowed) + var extractResult = FormattedStringValueExtracter.Extract(origin, url, ignoreCase: true); + if (extractResult.IsMatch) { - return true; + return extractResult.Matches.Aggregate(url, (current, nameValue) => current.Replace($"{{{nameValue.Name}}}", nameValue.Value)) + .Contains(origin, StringComparison.OrdinalIgnoreCase); } - foreach (var url in allowedOrigins) + if (url.Replace("{0}.", "").Contains(origin, StringComparison.OrdinalIgnoreCase)) { - var extractResult = FormattedStringValueExtracter.Extract(origin, url, ignoreCase: true); - if (extractResult.IsMatch) - { - return extractResult.Matches.Aggregate(url, (current, nameValue) => current.Replace($"{{{nameValue.Name}}}", nameValue.Value)) - .Contains(origin, StringComparison.OrdinalIgnoreCase); - } - - if (url.Replace("{0}.", "").Contains(origin, StringComparison.OrdinalIgnoreCase)) - { - return true; - } + return true; } - - return false; } + + return false; } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AllowedCorsOriginsCacheItem.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AllowedCorsOriginsCacheItem.cs index 0f9babd1c2..e458d7af67 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AllowedCorsOriginsCacheItem.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AllowedCorsOriginsCacheItem.cs @@ -1,9 +1,8 @@ -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class AllowedCorsOriginsCacheItem { - public class AllowedCorsOriginsCacheItem - { - public const string AllOrigins = "AllOrigins"; + public const string AllOrigins = "AllOrigins"; - public string[] AllowedOrigins { get; set; } - } -} \ No newline at end of file + public string[] AllowedOrigins { get; set; } +} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AllowedCorsOriginsCacheItemInvalidator.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AllowedCorsOriginsCacheItemInvalidator.cs index 53bfedd128..a8026961e9 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AllowedCorsOriginsCacheItemInvalidator.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AllowedCorsOriginsCacheItemInvalidator.cs @@ -5,28 +5,27 @@ using Volo.Abp.Domain.Entities.Events; using Volo.Abp.EventBus; using Volo.Abp.IdentityServer.Clients; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class AllowedCorsOriginsCacheItemInvalidator : + ILocalEventHandler>, + ILocalEventHandler>, + ITransientDependency { - public class AllowedCorsOriginsCacheItemInvalidator : - ILocalEventHandler>, - ILocalEventHandler>, - ITransientDependency + protected IDistributedCache Cache { get; } + + public AllowedCorsOriginsCacheItemInvalidator(IDistributedCache cache) { - protected IDistributedCache Cache { get; } + Cache = cache; + } - public AllowedCorsOriginsCacheItemInvalidator(IDistributedCache cache) - { - Cache = cache; - } - - public virtual async Task HandleEventAsync(EntityChangedEventData eventData) - { - await Cache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins); - } + public virtual async Task HandleEventAsync(EntityChangedEventData eventData) + { + await Cache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins); + } - public virtual async Task HandleEventAsync(EntityChangedEventData eventData) - { - await Cache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins); - } + public virtual async Task HandleEventAsync(EntityChangedEventData eventData) + { + await Cache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins); } -} \ 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 index ba4809feab..25bd38ad10 100644 --- 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 @@ -3,35 +3,34 @@ using System.Collections.Generic; using System.Linq; using AutoMapper; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class AllowedSigningAlgorithmsConverter : + IValueConverter, string>, + IValueConverter> { - public class AllowedSigningAlgorithmsConverter : - IValueConverter, string>, - IValueConverter> - { - public static AllowedSigningAlgorithmsConverter Converter = new AllowedSigningAlgorithmsConverter(); + public static AllowedSigningAlgorithmsConverter Converter = new AllowedSigningAlgorithmsConverter(); - public string Convert(ICollection sourceMember, ResolutionContext context) + public string Convert(ICollection sourceMember, ResolutionContext context) + { + if (sourceMember == null || !sourceMember.Any()) { - if (sourceMember == null || !sourceMember.Any()) - { - return null; - } - return sourceMember.Aggregate((x, y) => $"{x},{y}"); + return null; } + return sourceMember.Aggregate((x, y) => $"{x},{y}"); + } - public ICollection Convert(string sourceMember, ResolutionContext context) + public ICollection Convert(string sourceMember, ResolutionContext context) + { + var list = new HashSet(); + if (!String.IsNullOrWhiteSpace(sourceMember)) { - var list = new HashSet(); - if (!String.IsNullOrWhiteSpace(sourceMember)) + sourceMember = sourceMember.Trim(); + foreach (var item in sourceMember.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Distinct()) { - sourceMember = sourceMember.Trim(); - foreach (var item in sourceMember.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Distinct()) - { - list.Add(item); - } + list.Add(item); } - return list; } + 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 0b682a632d..4fff0c7193 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 @@ -5,148 +5,147 @@ using IdentityServer4; using JetBrains.Annotations; using Volo.Abp.Domain.Entities.Auditing; -namespace Volo.Abp.IdentityServer.ApiResources +namespace Volo.Abp.IdentityServer.ApiResources; + +public class ApiResource : FullAuditedAggregateRoot { - public class ApiResource : FullAuditedAggregateRoot - { - [NotNull] - public virtual string Name { get; protected set; } + [NotNull] + public virtual string Name { get; protected set; } - public virtual string DisplayName { get; set; } + public virtual string DisplayName { get; set; } - public virtual string Description { get; set; } + public virtual string Description { get; set; } - public virtual bool Enabled { get; set; } + public virtual bool Enabled { get; set; } - public virtual string AllowedAccessTokenSigningAlgorithms { get; set; } + public virtual string AllowedAccessTokenSigningAlgorithms { get; set; } - public virtual bool ShowInDiscoveryDocument { get; set; } = true; + public virtual bool ShowInDiscoveryDocument { get; set; } = true; - public virtual List Secrets { get; protected set; } + public virtual List Secrets { get; protected set; } - public virtual List Scopes { get; protected set; } + public virtual List Scopes { get; protected set; } - public virtual List UserClaims { get; protected set; } + public virtual List UserClaims { get; protected set; } - public virtual List Properties { get; protected set; } + public virtual List Properties { get; protected set; } - protected ApiResource() - { + protected ApiResource() + { - } + } - public ApiResource(Guid id, [NotNull] string name, string displayName = null, string description = null) - : base(id) - { - Check.NotNull(name, nameof(name)); + public ApiResource(Guid id, [NotNull] string name, string displayName = null, string description = null) + : base(id) + { + Check.NotNull(name, nameof(name)); - Name = name; + Name = name; - DisplayName = displayName; - Description = description; + DisplayName = displayName; + Description = description; - Enabled = true; + Enabled = true; - Secrets = new List(); - Scopes = new List(); - UserClaims = new List(); - Properties = new List(); + Secrets = new List(); + Scopes = new List(); + UserClaims = new List(); + Properties = new List(); - Scopes.Add(new ApiResourceScope(id, name)); - } + Scopes.Add(new ApiResourceScope(id, name)); + } - public virtual void AddSecret( - [NotNull] string value, - DateTime? expiration = null, - string type = IdentityServerConstants.SecretTypes.SharedSecret, - string description = null) - { - Secrets.Add(new ApiResourceSecret(Id, value, expiration, type, description)); - } + public virtual void AddSecret( + [NotNull] string value, + DateTime? expiration = null, + string type = IdentityServerConstants.SecretTypes.SharedSecret, + string description = null) + { + Secrets.Add(new ApiResourceSecret(Id, value, expiration, type, description)); + } - public virtual void RemoveSecret([NotNull] string value, string type = IdentityServerConstants.SecretTypes.SharedSecret) - { - Secrets.RemoveAll(s => s.Value == value && s.Type == type); - } + public virtual void RemoveSecret([NotNull] string value, string type = IdentityServerConstants.SecretTypes.SharedSecret) + { + Secrets.RemoveAll(s => s.Value == value && s.Type == type); + } - public virtual ApiResourceSecret FindSecret([NotNull] string value, string type = IdentityServerConstants.SecretTypes.SharedSecret) - { - return Secrets.FirstOrDefault(s => s.Type == type && s.Value == value); - } + public virtual ApiResourceSecret FindSecret([NotNull] string value, string type = IdentityServerConstants.SecretTypes.SharedSecret) + { + return Secrets.FirstOrDefault(s => s.Type == type && s.Value == value); + } - public virtual ApiResourceScope AddScope([NotNull] string scope) - { - var apiResourceScope = new ApiResourceScope(Id, scope); - Scopes.Add(apiResourceScope); - return apiResourceScope; - } + public virtual ApiResourceScope AddScope([NotNull] string scope) + { + var apiResourceScope = new ApiResourceScope(Id, scope); + Scopes.Add(apiResourceScope); + return apiResourceScope; + } - public virtual void AddUserClaim([NotNull] string type) - { - UserClaims.Add(new ApiResourceClaim(Id, type)); - } + public virtual void AddUserClaim([NotNull] string type) + { + UserClaims.Add(new ApiResourceClaim(Id, type)); + } - public virtual void RemoveAllUserClaims() - { - UserClaims.Clear(); - } + public virtual void RemoveAllUserClaims() + { + UserClaims.Clear(); + } - public virtual void RemoveClaim(string type) - { - UserClaims.RemoveAll(c => c.Type == type); - } + 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 ApiResourceClaim FindClaim(string type) + { + return UserClaims.FirstOrDefault(c => c.Type == type); + } - public virtual void RemoveAllSecrets() - { - Secrets.Clear(); - } + public virtual void RemoveAllSecrets() + { + Secrets.Clear(); + } - public virtual void RemoveAllScopes() - { - Scopes.Clear(); - } + public virtual void RemoveAllScopes() + { + Scopes.Clear(); + } - public virtual void RemoveScope(string scope) - { - Scopes.RemoveAll(r => r.Scope == scope); - } + public virtual void RemoveScope(string scope) + { + Scopes.RemoveAll(r => r.Scope == scope); + } - public virtual ApiResourceScope FindScope(string scope) - { - return Scopes.FirstOrDefault(r => r.Scope == scope); - } + public virtual ApiResourceScope FindScope(string scope) + { + return Scopes.FirstOrDefault(r => r.Scope == scope); + } - public virtual void AddProperty([NotNull] string key, string value) + public virtual void AddProperty([NotNull] string key, string value) + { + var property = FindProperty(key); + if (property == null) { - var property = FindProperty(key); - if (property == null) - { - Properties.Add(new ApiResourceProperty(Id, key, value)); - } - else - { - property.Value = value; - } + Properties.Add(new ApiResourceProperty(Id, key, value)); } - - public virtual void RemoveAllProperties() + else { - Properties.Clear(); + property.Value = value; } + } - public virtual void RemoveProperty(string key) - { - Properties.RemoveAll(r => r.Key == key); - } + public virtual void RemoveAllProperties() + { + Properties.Clear(); + } - public virtual ApiResourceProperty FindProperty(string key) - { - return Properties.FirstOrDefault(r => r.Key == key); - } + public virtual void RemoveProperty(string key) + { + Properties.RemoveAll(r => r.Key == key); + } + + public virtual ApiResourceProperty FindProperty(string key) + { + return Properties.FirstOrDefault(r => r.Key == key); } } 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 772f6dcde7..42304433f5 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 @@ -1,31 +1,30 @@ using System; using JetBrains.Annotations; -namespace Volo.Abp.IdentityServer.ApiResources +namespace Volo.Abp.IdentityServer.ApiResources; + +public class ApiResourceClaim : UserClaim { - public class ApiResourceClaim : UserClaim - { - public virtual Guid ApiResourceId { get; set; } + public virtual Guid ApiResourceId { get; set; } - protected ApiResourceClaim() - { + protected ApiResourceClaim() + { - } + } - public virtual bool Equals(Guid apiResourceId, [NotNull] string type) - { - return ApiResourceId == apiResourceId && Type == type; - } + public virtual bool Equals(Guid apiResourceId, [NotNull] string type) + { + return ApiResourceId == apiResourceId && Type == type; + } - protected internal ApiResourceClaim(Guid apiResourceId, [NotNull] string type) - : base(type) - { - ApiResourceId = apiResourceId; - } + protected internal ApiResourceClaim(Guid apiResourceId, [NotNull] string type) + : base(type) + { + ApiResourceId = apiResourceId; + } - public override object[] GetKeys() - { - return new object[] {ApiResourceId, Type}; - } + public override object[] GetKeys() + { + return new object[] { ApiResourceId, Type }; } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceProperty.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceProperty.cs index 7b6257c771..79e63a8c01 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceProperty.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceProperty.cs @@ -2,38 +2,37 @@ using JetBrains.Annotations; using Volo.Abp.Domain.Entities; -namespace Volo.Abp.IdentityServer.ApiResources +namespace Volo.Abp.IdentityServer.ApiResources; + +public class ApiResourceProperty : Entity { - public class ApiResourceProperty : Entity - { - public virtual Guid ApiResourceId { get; protected set; } + public virtual Guid ApiResourceId { get; protected set; } - public virtual string Key { get; set; } + public virtual string Key { get; set; } - public virtual string Value { get; set; } + public virtual string Value { get; set; } - protected ApiResourceProperty() - { + protected ApiResourceProperty() + { - } + } - public virtual bool Equals(Guid aiResourceId, [NotNull] string key, string value) - { - return ApiResourceId == aiResourceId && Key == key && Value == value; - } + public virtual bool Equals(Guid aiResourceId, [NotNull] string key, string value) + { + return ApiResourceId == aiResourceId && Key == key && Value == value; + } - protected internal ApiResourceProperty(Guid aiResourceId, [NotNull] string key, [NotNull] string value) - { - Check.NotNull(key, nameof(key)); + protected internal ApiResourceProperty(Guid aiResourceId, [NotNull] string key, [NotNull] string value) + { + Check.NotNull(key, nameof(key)); - ApiResourceId = aiResourceId; - Key = key; - Value = value; - } + ApiResourceId = aiResourceId; + Key = key; + Value = value; + } - public override object[] GetKeys() - { - return new object[] { ApiResourceId, Key }; - } + public override object[] GetKeys() + { + return new object[] { ApiResourceId, Key }; } } 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 index 4da2beaa3f..9a6de02f4e 100644 --- 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 @@ -2,37 +2,36 @@ using JetBrains.Annotations; using Volo.Abp.Domain.Entities; -namespace Volo.Abp.IdentityServer.ApiResources +namespace Volo.Abp.IdentityServer.ApiResources; + +public class ApiResourceScope : Entity { - public class ApiResourceScope : Entity - { - public virtual Guid ApiResourceId { get; protected set; } + public virtual Guid ApiResourceId { get; protected set; } - public virtual string Scope { get; set; } + public virtual string Scope { get; set; } - protected ApiResourceScope() - { + protected ApiResourceScope() + { - } + } - public virtual bool Equals(Guid apiResourceId, [NotNull] string scope) - { - return ApiResourceId == apiResourceId && Scope == scope; - } + 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)); + protected internal ApiResourceScope( + Guid apiResourceId, + [NotNull] string scope) + { + Check.NotNull(scope, nameof(scope)); - ApiResourceId = apiResourceId; - Scope = scope; - } + ApiResourceId = apiResourceId; + Scope = scope; + } - public override object[] GetKeys() - { - return new object[] { ApiResourceId, Scope }; - } + public override object[] GetKeys() + { + return new object[] { ApiResourceId, Scope }; } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceSecret.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceSecret.cs index dcc6b04768..365c2dece1 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceSecret.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceSecret.cs @@ -2,40 +2,39 @@ using IdentityServer4; using JetBrains.Annotations; -namespace Volo.Abp.IdentityServer.ApiResources +namespace Volo.Abp.IdentityServer.ApiResources; + +public class ApiResourceSecret : Secret { - public class ApiResourceSecret : Secret - { - public virtual Guid ApiResourceId { get; protected set; } + public virtual Guid ApiResourceId { get; protected set; } - protected ApiResourceSecret() - { + protected ApiResourceSecret() + { - } + } - public virtual bool Equals(Guid apiResourceId, [NotNull] string value, string type = IdentityServerConstants.SecretTypes.SharedSecret) - { - return ApiResourceId == apiResourceId && Value == value && Type == type; - } + public virtual bool Equals(Guid apiResourceId, [NotNull] string value, string type = IdentityServerConstants.SecretTypes.SharedSecret) + { + return ApiResourceId == apiResourceId && Value == value && Type == type; + } - protected internal ApiResourceSecret( - Guid apiResourceId, - [NotNull] string value, - DateTime? expiration = null, - string type = IdentityServerConstants.SecretTypes.SharedSecret, - string description = null - ) : base( - value, - expiration, - type, - description) - { - ApiResourceId = apiResourceId; - } + protected internal ApiResourceSecret( + Guid apiResourceId, + [NotNull] string value, + DateTime? expiration = null, + string type = IdentityServerConstants.SecretTypes.SharedSecret, + string description = null + ) : base( + value, + expiration, + type, + description) + { + ApiResourceId = apiResourceId; + } - public override object[] GetKeys() - { - return new object[] { ApiResourceId, Type, Value }; - } + public override object[] GetKeys() + { + return new object[] { ApiResourceId, Type, Value }; } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/IApiResourceRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/IApiResourceRepository.cs index d1f60bcb7b..e1347c5144 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/IApiResourceRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/IApiResourceRepository.cs @@ -4,46 +4,45 @@ using System.Threading; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories; -namespace Volo.Abp.IdentityServer.ApiResources +namespace Volo.Abp.IdentityServer.ApiResources; + +public interface IApiResourceRepository : IBasicRepository { - public interface IApiResourceRepository : IBasicRepository - { - Task FindByNameAsync( - string apiResourceName, - bool includeDetails = true, - CancellationToken cancellationToken = default - ); + Task FindByNameAsync( + string apiResourceName, + bool includeDetails = true, + CancellationToken cancellationToken = default + ); - Task> FindByNameAsync( - string[] apiResourceNames, - bool includeDetails = true, - CancellationToken cancellationToken = default - ); + Task> FindByNameAsync( + string[] apiResourceNames, + bool includeDetails = true, + CancellationToken cancellationToken = default + ); - Task> GetListByScopesAsync( - string[] scopeNames, - bool includeDetails = false, - CancellationToken cancellationToken = default - ); + Task> GetListByScopesAsync( + string[] scopeNames, + bool includeDetails = false, + CancellationToken cancellationToken = default + ); - Task> GetListAsync( - string sorting, - int skipCount, - int maxResultCount, - string filter = null, - bool includeDetails = false, - CancellationToken cancellationToken = default - ); + Task> GetListAsync( + string sorting, + int skipCount, + int maxResultCount, + string filter = null, + bool includeDetails = false, + CancellationToken cancellationToken = default + ); - Task GetCountAsync( - string filter = null, - CancellationToken cancellationToken = default - ); + Task GetCountAsync( + string filter = null, + CancellationToken cancellationToken = default + ); - Task CheckNameExistAsync( - string name, - Guid? expectedId = null, - CancellationToken cancellationToken = default - ); - } + Task CheckNameExistAsync( + string name, + Guid? expectedId = null, + CancellationToken cancellationToken = default + ); } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiScopes/ApiScope.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiScopes/ApiScope.cs index 60945195d9..f36014ecb8 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiScopes/ApiScope.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiScopes/ApiScope.cs @@ -4,105 +4,104 @@ using System.Linq; using JetBrains.Annotations; using Volo.Abp.Domain.Entities.Auditing; -namespace Volo.Abp.IdentityServer.ApiScopes +namespace Volo.Abp.IdentityServer.ApiScopes; + +public class ApiScope : FullAuditedAggregateRoot { - public class ApiScope : FullAuditedAggregateRoot - { - public virtual bool Enabled { get; set; } + public virtual bool Enabled { get; set; } - [NotNull] - public virtual string Name { get; protected set; } + [NotNull] + public virtual string Name { get; protected set; } - public virtual string DisplayName { get; set; } + public virtual string DisplayName { get; set; } - public virtual string Description { get; set; } + public virtual string Description { get; set; } - public virtual bool Required { get; set; } + public virtual bool Required { get; set; } - public virtual bool Emphasize { get; set; } + public virtual bool Emphasize { get; set; } - public virtual bool ShowInDiscoveryDocument { get; set; } + public virtual bool ShowInDiscoveryDocument { get; set; } - public virtual List UserClaims { get; protected set; } + public virtual List UserClaims { get; protected set; } - public virtual List Properties { get; protected set; } + public virtual List Properties { get; protected set; } - protected ApiScope() - { + protected ApiScope() + { - } + } - public ApiScope( - Guid id, - [NotNull] string name, - string displayName = null, - string description = null, - bool required = false, - bool emphasize = false, - bool showInDiscoveryDocument = true, - bool enabled = true - ) : base(id) - { - Check.NotNull(name, nameof(name)); - - Name = name; - DisplayName = displayName ?? name; - Description = description; - Required = required; - Emphasize = emphasize; - ShowInDiscoveryDocument = showInDiscoveryDocument; - Enabled = enabled; - - UserClaims = new List(); - Properties = new List(); - } + public ApiScope( + Guid id, + [NotNull] string name, + string displayName = null, + string description = null, + bool required = false, + bool emphasize = false, + bool showInDiscoveryDocument = true, + bool enabled = true + ) : base(id) + { + Check.NotNull(name, nameof(name)); + + Name = name; + DisplayName = displayName ?? name; + Description = description; + Required = required; + Emphasize = emphasize; + ShowInDiscoveryDocument = showInDiscoveryDocument; + Enabled = enabled; + + UserClaims = new List(); + Properties = new List(); + } - public virtual void AddUserClaim([NotNull] string type) - { - UserClaims.Add(new ApiScopeClaim(Id, type)); - } + public virtual void AddUserClaim([NotNull] string type) + { + UserClaims.Add(new ApiScopeClaim(Id, type)); + } - public virtual void RemoveAllUserClaims() - { - UserClaims.Clear(); - } + public virtual void RemoveAllUserClaims() + { + UserClaims.Clear(); + } - public virtual void RemoveClaim(string type) - { - UserClaims.RemoveAll(r => r.Type == type); - } + public virtual void RemoveClaim(string type) + { + UserClaims.RemoveAll(r => r.Type == type); + } - public virtual ApiScopeClaim FindClaim(string type) - { - return UserClaims.FirstOrDefault(r => r.Type == type); - } + public virtual ApiScopeClaim FindClaim(string type) + { + return UserClaims.FirstOrDefault(r => r.Type == type); + } - public virtual void AddProperty([NotNull] string key, string value) + public virtual void AddProperty([NotNull] string key, string value) + { + var property = FindProperty(key); + if (property == null) { - var property = FindProperty(key); - if (property == null) - { - Properties.Add(new ApiScopeProperty(Id, key, value)); - } - else - { - property.Value = value; - } + Properties.Add(new ApiScopeProperty(Id, key, value)); } - - public virtual void RemoveAllProperties() + else { - Properties.Clear(); + property.Value = value; } + } - public virtual void RemoveProperty(string key) - { - Properties.RemoveAll(r => r.Key == key); - } + public virtual void RemoveAllProperties() + { + Properties.Clear(); + } - public virtual ApiScopeProperty FindProperty(string key) - { - return Properties.FirstOrDefault(r => r.Key == key); - } + public virtual void RemoveProperty(string key) + { + Properties.RemoveAll(r => r.Key == key); + } + + public virtual ApiScopeProperty FindProperty(string key) + { + return Properties.FirstOrDefault(r => r.Key == key); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiScopes/ApiScopeClaim.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiScopes/ApiScopeClaim.cs index 95519195e7..b7c1206142 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiScopes/ApiScopeClaim.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiScopes/ApiScopeClaim.cs @@ -1,31 +1,30 @@ using System; using JetBrains.Annotations; -namespace Volo.Abp.IdentityServer.ApiScopes +namespace Volo.Abp.IdentityServer.ApiScopes; + +public class ApiScopeClaim : UserClaim { - public class ApiScopeClaim : UserClaim - { - public Guid ApiScopeId { get; protected set; } + public Guid ApiScopeId { get; protected set; } - protected ApiScopeClaim() - { + protected ApiScopeClaim() + { - } + } - public virtual bool Equals(Guid apiScopeId, [NotNull] string type) - { - return ApiScopeId == apiScopeId && Type == type; - } + public virtual bool Equals(Guid apiScopeId, [NotNull] string type) + { + return ApiScopeId == apiScopeId && Type == type; + } - protected internal ApiScopeClaim(Guid apiScopeId, [NotNull] string type) - : base(type) - { - ApiScopeId = apiScopeId; - } + protected internal ApiScopeClaim(Guid apiScopeId, [NotNull] string type) + : base(type) + { + ApiScopeId = apiScopeId; + } - public override object[] GetKeys() - { - return new object[] { ApiScopeId, Type }; - } + public override object[] GetKeys() + { + return new object[] { ApiScopeId, Type }; } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiScopes/ApiScopeProperty.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiScopes/ApiScopeProperty.cs index b6e5d7fbe8..52cf0e678b 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiScopes/ApiScopeProperty.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiScopes/ApiScopeProperty.cs @@ -2,38 +2,37 @@ using JetBrains.Annotations; using Volo.Abp.Domain.Entities; -namespace Volo.Abp.IdentityServer.ApiScopes +namespace Volo.Abp.IdentityServer.ApiScopes; + +public class ApiScopeProperty : Entity { - public class ApiScopeProperty : Entity - { - public virtual Guid ApiScopeId { get; set; } + public virtual Guid ApiScopeId { get; set; } - public virtual string Key { get; set; } + public virtual string Key { get; set; } - public virtual string Value { get; set; } + public virtual string Value { get; set; } - protected ApiScopeProperty() - { + protected ApiScopeProperty() + { - } + } - public virtual bool Equals(Guid apiScopeId, [NotNull] string key, string value) - { - return ApiScopeId == apiScopeId && Key == key && Value == value; - } + 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)); + protected internal ApiScopeProperty(Guid apiScopeId, [NotNull] string key, [NotNull] string value) + { + Check.NotNull(key, nameof(key)); - ApiScopeId = apiScopeId; - Key = key; - Value = value; - } + ApiScopeId = apiScopeId; + Key = key; + Value = value; + } - public override object[] GetKeys() - { - return new object[] { ApiScopeId, Key }; - } + public override object[] GetKeys() + { + return new object[] { ApiScopeId, Key }; } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiScopes/IApiScopeRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiScopes/IApiScopeRepository.cs index 6748b0e106..b49c442b6d 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiScopes/IApiScopeRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiScopes/IApiScopeRepository.cs @@ -4,40 +4,39 @@ using System.Threading; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories; -namespace Volo.Abp.IdentityServer.ApiScopes +namespace Volo.Abp.IdentityServer.ApiScopes; + +public interface IApiScopeRepository : IBasicRepository { - public interface IApiScopeRepository : IBasicRepository - { - Task FindByNameAsync( - string scopeName, - bool includeDetails = true, - CancellationToken cancellationToken = default - ); + Task FindByNameAsync( + string scopeName, + bool includeDetails = true, + CancellationToken cancellationToken = default + ); - Task> GetListByNameAsync( - string[] scopeNames, - bool includeDetails = false, - CancellationToken cancellationToken = default - ); + Task> GetListByNameAsync( + string[] scopeNames, + bool includeDetails = false, + CancellationToken cancellationToken = default + ); - Task> GetListAsync( - string sorting, - int skipCount, - int maxResultCount, - string filter = null, - bool includeDetails = false, - CancellationToken cancellationToken = default - ); + Task> GetListAsync( + string sorting, + int skipCount, + int maxResultCount, + string filter = null, + bool includeDetails = false, + CancellationToken cancellationToken = default + ); - Task GetCountAsync( - string filter = null, - CancellationToken cancellationToken = default - ); + Task GetCountAsync( + string filter = null, + CancellationToken cancellationToken = default + ); - Task CheckNameExistAsync( - string name, - Guid? expectedId = null, - CancellationToken cancellationToken = default - ); - } + Task CheckNameExistAsync( + string name, + Guid? expectedId = null, + CancellationToken cancellationToken = default + ); } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpProfileService.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpProfileService.cs index e09315c69f..3007c0971d 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpProfileService.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpProfileService.cs @@ -8,43 +8,42 @@ using Volo.Abp.MultiTenancy; using Volo.Abp.Uow; using IdentityUser = Volo.Abp.Identity.IdentityUser; -namespace Volo.Abp.IdentityServer.AspNetIdentity +namespace Volo.Abp.IdentityServer.AspNetIdentity; + +public class AbpProfileService : ProfileService { - public class AbpProfileService : ProfileService - { - protected ICurrentTenant CurrentTenant { get; } + protected ICurrentTenant CurrentTenant { get; } - public AbpProfileService( - IdentityUserManager userManager, - IUserClaimsPrincipalFactory claimsFactory, - ICurrentTenant currentTenant) - : base(userManager, claimsFactory) - { - CurrentTenant = currentTenant; - } + public AbpProfileService( + IdentityUserManager userManager, + IUserClaimsPrincipalFactory claimsFactory, + ICurrentTenant currentTenant) + : base(userManager, claimsFactory) + { + CurrentTenant = currentTenant; + } - [UnitOfWork] - public override async Task GetProfileDataAsync(ProfileDataRequestContext context) + [UnitOfWork] + public override async Task GetProfileDataAsync(ProfileDataRequestContext context) + { + using (CurrentTenant.Change(context.Subject.FindTenantId())) { - using (CurrentTenant.Change(context.Subject.FindTenantId())) - { - await base.GetProfileDataAsync(context); - } + await base.GetProfileDataAsync(context); } + } - [UnitOfWork] - public override async Task IsActiveAsync(IsActiveContext context) + [UnitOfWork] + public override async Task IsActiveAsync(IsActiveContext context) + { + using (CurrentTenant.Change(context.Subject.FindTenantId())) { - using (CurrentTenant.Change(context.Subject.FindTenantId())) - { - await base.IsActiveAsync(context); - } + await base.IsActiveAsync(context); } + } - [UnitOfWork] - public override Task IsUserActiveAsync(IdentityUser user) - { - return Task.FromResult(user.IsActive); - } + [UnitOfWork] + public override Task IsUserActiveAsync(IdentityUser user) + { + return Task.FromResult(user.IsActive); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs index 4d7d049949..77181a8b8b 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs @@ -23,248 +23,247 @@ using Volo.Abp.Uow; using Volo.Abp.Validation; using IdentityUser = Volo.Abp.Identity.IdentityUser; -namespace Volo.Abp.IdentityServer.AspNetIdentity +namespace Volo.Abp.IdentityServer.AspNetIdentity; + +public class AbpResourceOwnerPasswordValidator : IResourceOwnerPasswordValidator { - public class AbpResourceOwnerPasswordValidator : IResourceOwnerPasswordValidator + protected SignInManager SignInManager { get; } + protected UserManager UserManager { get; } + protected IdentitySecurityLogManager IdentitySecurityLogManager { get; } + protected ILogger> Logger { get; } + protected IStringLocalizer Localizer { get; } + protected IHybridServiceScopeFactory ServiceScopeFactory { get; } + protected AbpIdentityOptions AbpIdentityOptions { get; } + protected IOptions IdentityOptions { get; } + + public AbpResourceOwnerPasswordValidator( + UserManager userManager, + SignInManager signInManager, + IdentitySecurityLogManager identitySecurityLogManager, + ILogger> logger, + IStringLocalizer localizer, + IOptions abpIdentityOptions, + IHybridServiceScopeFactory serviceScopeFactory, + IOptions identityOptions) { - protected SignInManager SignInManager { get; } - protected UserManager UserManager { get; } - protected IdentitySecurityLogManager IdentitySecurityLogManager { get; } - protected ILogger> Logger { get; } - protected IStringLocalizer Localizer { get; } - protected IHybridServiceScopeFactory ServiceScopeFactory { get; } - protected AbpIdentityOptions AbpIdentityOptions { get; } - protected IOptions IdentityOptions { get; } + UserManager = userManager; + SignInManager = signInManager; + IdentitySecurityLogManager = identitySecurityLogManager; + Logger = logger; + Localizer = localizer; + ServiceScopeFactory = serviceScopeFactory; + AbpIdentityOptions = abpIdentityOptions.Value; + IdentityOptions = identityOptions; + } - public AbpResourceOwnerPasswordValidator( - UserManager userManager, - SignInManager signInManager, - IdentitySecurityLogManager identitySecurityLogManager, - ILogger> logger, - IStringLocalizer localizer, - IOptions abpIdentityOptions, - IHybridServiceScopeFactory serviceScopeFactory, - IOptions identityOptions) + /// + /// https://github.com/IdentityServer/IdentityServer4/blob/master/src/AspNetIdentity/src/ResourceOwnerPasswordValidator.cs#L53 + /// + /// + /// + [UnitOfWork] + public virtual async Task ValidateAsync(ResourceOwnerPasswordValidationContext context) + { + using (var scope = ServiceScopeFactory.CreateScope()) { - UserManager = userManager; - SignInManager = signInManager; - IdentitySecurityLogManager = identitySecurityLogManager; - Logger = logger; - Localizer = localizer; - ServiceScopeFactory = serviceScopeFactory; - AbpIdentityOptions = abpIdentityOptions.Value; - IdentityOptions = identityOptions; - } + await ReplaceEmailToUsernameOfInputIfNeeds(context); - /// - /// https://github.com/IdentityServer/IdentityServer4/blob/master/src/AspNetIdentity/src/ResourceOwnerPasswordValidator.cs#L53 - /// - /// - /// - [UnitOfWork] - public virtual async Task ValidateAsync(ResourceOwnerPasswordValidationContext context) - { - using (var scope = ServiceScopeFactory.CreateScope()) - { - await ReplaceEmailToUsernameOfInputIfNeeds(context); + IdentityUser user = null; - IdentityUser user = null; - - if (AbpIdentityOptions.ExternalLoginProviders.Any()) + if (AbpIdentityOptions.ExternalLoginProviders.Any()) + { + foreach (var externalLoginProviderInfo in AbpIdentityOptions.ExternalLoginProviders.Values) { - foreach (var externalLoginProviderInfo in AbpIdentityOptions.ExternalLoginProviders.Values) - { - var externalLoginProvider = (IExternalLoginProvider) scope.ServiceProvider - .GetRequiredService(externalLoginProviderInfo.Type); + var externalLoginProvider = (IExternalLoginProvider)scope.ServiceProvider + .GetRequiredService(externalLoginProviderInfo.Type); - if (await externalLoginProvider.TryAuthenticateAsync(context.UserName, context.Password)) - { - user = await UserManager.FindByNameAsync(context.UserName); - if (user == null) - { - user = await externalLoginProvider.CreateUserAsync(context.UserName, externalLoginProviderInfo.Name); - } - else - { - await externalLoginProvider.UpdateUserAsync(user, externalLoginProviderInfo.Name); - } - - await SetSuccessResultAsync(context, user); - return; - } - } - } - - user = await UserManager.FindByNameAsync(context.UserName); - string errorDescription; - if (user != null) - { - await IdentityOptions.SetAsync(); - var result = await SignInManager.CheckPasswordSignInAsync(user, context.Password, true); - if (result.Succeeded) + if (await externalLoginProvider.TryAuthenticateAsync(context.UserName, context.Password)) { - if (await IsTfaEnabledAsync(user)) + user = await UserManager.FindByNameAsync(context.UserName); + if (user == null) { - await HandleTwoFactorLoginAsync(context, user); + user = await externalLoginProvider.CreateUserAsync(context.UserName, externalLoginProviderInfo.Name); } else { - await SetSuccessResultAsync(context, user); + await externalLoginProvider.UpdateUserAsync(user, externalLoginProviderInfo.Name); } + + await SetSuccessResultAsync(context, user); return; } + } + } - if (result.IsLockedOut) - { - Logger.LogInformation("Authentication failed for username: {username}, reason: locked out", context.UserName); - errorDescription = Localizer["UserLockedOut"]; - } - else if (result.IsNotAllowed) + user = await UserManager.FindByNameAsync(context.UserName); + string errorDescription; + if (user != null) + { + await IdentityOptions.SetAsync(); + var result = await SignInManager.CheckPasswordSignInAsync(user, context.Password, true); + if (result.Succeeded) + { + if (await IsTfaEnabledAsync(user)) { - Logger.LogInformation("Authentication failed for username: {username}, reason: not allowed", context.UserName); - errorDescription = Localizer["LoginIsNotAllowed"]; + await HandleTwoFactorLoginAsync(context, user); } else { - Logger.LogInformation("Authentication failed for username: {username}, reason: invalid credentials", context.UserName); - errorDescription = Localizer["InvalidUserNameOrPassword"]; + await SetSuccessResultAsync(context, user); } + return; + } - await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext - { - Identity = IdentityServerSecurityLogIdentityConsts.IdentityServer, - Action = result.ToIdentitySecurityLogAction(), - UserName = context.UserName, - ClientId = await FindClientIdAsync(context) - }); + if (result.IsLockedOut) + { + Logger.LogInformation("Authentication failed for username: {username}, reason: locked out", context.UserName); + errorDescription = Localizer["UserLockedOut"]; } - else + else if (result.IsNotAllowed) { - Logger.LogInformation("No user found matching username: {username}", context.UserName); - errorDescription = Localizer["InvalidUsername"]; - - await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext() - { - Identity = IdentityServerSecurityLogIdentityConsts.IdentityServer, - Action = IdentityServerSecurityLogActionConsts.LoginInvalidUserName, - UserName = context.UserName, - ClientId = await FindClientIdAsync(context) - }); + Logger.LogInformation("Authentication failed for username: {username}, reason: not allowed", context.UserName); + errorDescription = Localizer["LoginIsNotAllowed"]; } - - context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, errorDescription); - } - } - - protected virtual async Task HandleTwoFactorLoginAsync(ResourceOwnerPasswordValidationContext context, IdentityUser user) - { - var twoFactorProvider = context.Request?.Raw?["TwoFactorProvider"]; - var twoFactorCode = context.Request?.Raw?["TwoFactorCode"]; - if (!twoFactorProvider.IsNullOrWhiteSpace() && !twoFactorCode.IsNullOrWhiteSpace()) - { - var providers = await UserManager.GetValidTwoFactorProvidersAsync(user); - if (providers.Contains(twoFactorProvider) && await UserManager.VerifyTwoFactorTokenAsync(user, twoFactorProvider, twoFactorCode)) + else { - await SetSuccessResultAsync(context, user); - return; + Logger.LogInformation("Authentication failed for username: {username}, reason: invalid credentials", context.UserName); + errorDescription = Localizer["InvalidUserNameOrPassword"]; } - Logger.LogInformation("Authentication failed for username: {username}, reason: InvalidAuthenticatorCode", context.UserName); - context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, Localizer["InvalidAuthenticatorCode"]); - } - else - { - Logger.LogInformation("Authentication failed for username: {username}, reason: RequiresTwoFactor", context.UserName); - var twoFactorToken = await UserManager.GenerateUserTokenAsync(user, TokenOptions.DefaultProvider, nameof(SignInResult.RequiresTwoFactor)); - context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, nameof(SignInResult.RequiresTwoFactor), - new Dictionary() - { - {"userId", user.Id}, - {"twoFactorToken", twoFactorToken} - }); - await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext { Identity = IdentityServerSecurityLogIdentityConsts.IdentityServer, - Action = IdentityServerSecurityLogActionConsts.LoginRequiresTwoFactor, + Action = result.ToIdentitySecurityLogAction(), UserName = context.UserName, ClientId = await FindClientIdAsync(context) }); } - } - - protected virtual async Task SetSuccessResultAsync(ResourceOwnerPasswordValidationContext context, IdentityUser user) - { - var sub = await UserManager.GetUserIdAsync(user); - - Logger.LogInformation("Credentials validated for username: {username}", context.UserName); - - var additionalClaims = new List(); - - await AddCustomClaimsAsync(additionalClaims, user, context); - - context.Result = new GrantValidationResult( - sub, - OidcConstants.AuthenticationMethods.Password, - additionalClaims.ToArray() - ); + else + { + Logger.LogInformation("No user found matching username: {username}", context.UserName); + errorDescription = Localizer["InvalidUsername"]; - await IdentitySecurityLogManager.SaveAsync( - new IdentitySecurityLogContext + await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext() { Identity = IdentityServerSecurityLogIdentityConsts.IdentityServer, - Action = IdentityServerSecurityLogActionConsts.LoginSucceeded, + Action = IdentityServerSecurityLogActionConsts.LoginInvalidUserName, UserName = context.UserName, ClientId = await FindClientIdAsync(context) - } - ); + }); + } + + context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, errorDescription); } + } - protected virtual async Task ReplaceEmailToUsernameOfInputIfNeeds(ResourceOwnerPasswordValidationContext context) + protected virtual async Task HandleTwoFactorLoginAsync(ResourceOwnerPasswordValidationContext context, IdentityUser user) + { + var twoFactorProvider = context.Request?.Raw?["TwoFactorProvider"]; + var twoFactorCode = context.Request?.Raw?["TwoFactorCode"]; + if (!twoFactorProvider.IsNullOrWhiteSpace() && !twoFactorCode.IsNullOrWhiteSpace()) { - if (!ValidationHelper.IsValidEmailAddress(context.UserName)) + var providers = await UserManager.GetValidTwoFactorProvidersAsync(user); + if (providers.Contains(twoFactorProvider) && await UserManager.VerifyTwoFactorTokenAsync(user, twoFactorProvider, twoFactorCode)) { + await SetSuccessResultAsync(context, user); return; } - var userByUsername = await UserManager.FindByNameAsync(context.UserName); - if (userByUsername != null) + Logger.LogInformation("Authentication failed for username: {username}, reason: InvalidAuthenticatorCode", context.UserName); + context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, Localizer["InvalidAuthenticatorCode"]); + } + else + { + Logger.LogInformation("Authentication failed for username: {username}, reason: RequiresTwoFactor", context.UserName); + var twoFactorToken = await UserManager.GenerateUserTokenAsync(user, TokenOptions.DefaultProvider, nameof(SignInResult.RequiresTwoFactor)); + context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, nameof(SignInResult.RequiresTwoFactor), + new Dictionary() + { + {"userId", user.Id}, + {"twoFactorToken", twoFactorToken} + }); + + await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext { - return; - } + Identity = IdentityServerSecurityLogIdentityConsts.IdentityServer, + Action = IdentityServerSecurityLogActionConsts.LoginRequiresTwoFactor, + UserName = context.UserName, + ClientId = await FindClientIdAsync(context) + }); + } + } - var userByEmail = await UserManager.FindByEmailAsync(context.UserName); - if (userByEmail == null) + protected virtual async Task SetSuccessResultAsync(ResourceOwnerPasswordValidationContext context, IdentityUser user) + { + var sub = await UserManager.GetUserIdAsync(user); + + Logger.LogInformation("Credentials validated for username: {username}", context.UserName); + + var additionalClaims = new List(); + + await AddCustomClaimsAsync(additionalClaims, user, context); + + context.Result = new GrantValidationResult( + sub, + OidcConstants.AuthenticationMethods.Password, + additionalClaims.ToArray() + ); + + await IdentitySecurityLogManager.SaveAsync( + new IdentitySecurityLogContext { - return; + Identity = IdentityServerSecurityLogIdentityConsts.IdentityServer, + Action = IdentityServerSecurityLogActionConsts.LoginSucceeded, + UserName = context.UserName, + ClientId = await FindClientIdAsync(context) } + ); + } - context.UserName = userByEmail.UserName; + protected virtual async Task ReplaceEmailToUsernameOfInputIfNeeds(ResourceOwnerPasswordValidationContext context) + { + if (!ValidationHelper.IsValidEmailAddress(context.UserName)) + { + return; } - protected virtual Task FindClientIdAsync(ResourceOwnerPasswordValidationContext context) + var userByUsername = await UserManager.FindByNameAsync(context.UserName); + if (userByUsername != null) { - return Task.FromResult(context.Request?.Client?.ClientId); + return; } - protected virtual async Task IsTfaEnabledAsync(IdentityUser user) - => UserManager.SupportsUserTwoFactor && - await UserManager.GetTwoFactorEnabledAsync(user) && - (await UserManager.GetValidTwoFactorProvidersAsync(user)).Count > 0; - - protected virtual Task AddCustomClaimsAsync(List customClaims, IdentityUser user, ResourceOwnerPasswordValidationContext context) + var userByEmail = await UserManager.FindByEmailAsync(context.UserName); + if (userByEmail == null) { - if (user.TenantId.HasValue) - { - customClaims.Add( - new Claim( - AbpClaimTypes.TenantId, - user.TenantId?.ToString() - ) - ); - } + return; + } + + context.UserName = userByEmail.UserName; + } + + protected virtual Task FindClientIdAsync(ResourceOwnerPasswordValidationContext context) + { + return Task.FromResult(context.Request?.Client?.ClientId); + } + + protected virtual async Task IsTfaEnabledAsync(IdentityUser user) + => UserManager.SupportsUserTwoFactor && + await UserManager.GetTwoFactorEnabledAsync(user) && + (await UserManager.GetValidTwoFactorProvidersAsync(user)).Count > 0; - return Task.CompletedTask; + protected virtual Task AddCustomClaimsAsync(List customClaims, IdentityUser user, ResourceOwnerPasswordValidationContext context) + { + if (user.TenantId.HasValue) + { + customClaims.Add( + new Claim( + AbpClaimTypes.TenantId, + user.TenantId?.ToString() + ) + ); } + + return Task.CompletedTask; } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpUserClaimsFactory.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpUserClaimsFactory.cs index 219cb943d8..fd62e61c3e 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpUserClaimsFactory.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpUserClaimsFactory.cs @@ -8,83 +8,82 @@ using Microsoft.AspNetCore.Identity; using Volo.Abp.DependencyInjection; using IdentityUser = Volo.Abp.Identity.IdentityUser; -namespace Volo.Abp.IdentityServer.AspNetIdentity +namespace Volo.Abp.IdentityServer.AspNetIdentity; + +public class AbpUserClaimsFactory : IUserClaimsPrincipalFactory + where TUser : class { - public class AbpUserClaimsFactory : IUserClaimsPrincipalFactory - where TUser : class + private readonly IObjectAccessor> _inner; + private readonly UserManager _userManager; + + public AbpUserClaimsFactory(IObjectAccessor> inner, + UserManager userManager) + { + _inner = inner; + _userManager = userManager; + } + + public async Task CreateAsync(TUser user) { - private readonly IObjectAccessor> _inner; - private readonly UserManager _userManager; + var principal = await _inner.Value.CreateAsync(user); + var identity = principal.Identities.First(); - public AbpUserClaimsFactory(IObjectAccessor> inner, - UserManager userManager) + if (!identity.HasClaim(x => x.Type == JwtClaimTypes.Subject)) { - _inner = inner; - _userManager = userManager; + var sub = await _userManager.GetUserIdAsync(user); + identity.AddIfNotContains(new Claim(JwtClaimTypes.Subject, sub)); } - public async Task CreateAsync(TUser user) + var username = await _userManager.GetUserNameAsync(user); + var usernameClaim = identity.FindFirst(claim => + claim.Type == _userManager.Options.ClaimsIdentity.UserNameClaimType && claim.Value == username); + if (usernameClaim != null) { - var principal = await _inner.Value.CreateAsync(user); - var identity = principal.Identities.First(); - - if (!identity.HasClaim(x => x.Type == JwtClaimTypes.Subject)) - { - var sub = await _userManager.GetUserIdAsync(user); - identity.AddIfNotContains(new Claim(JwtClaimTypes.Subject, sub)); - } + identity.RemoveClaim(usernameClaim); + identity.AddIfNotContains(new Claim(JwtClaimTypes.PreferredUserName, username)); + } - var username = await _userManager.GetUserNameAsync(user); - var usernameClaim = identity.FindFirst(claim => - claim.Type == _userManager.Options.ClaimsIdentity.UserNameClaimType && claim.Value == username); - if (usernameClaim != null) - { - identity.RemoveClaim(usernameClaim); - identity.AddIfNotContains(new Claim(JwtClaimTypes.PreferredUserName, username)); - } + if (!identity.HasClaim(x => x.Type == JwtClaimTypes.Name)) + { + identity.AddIfNotContains(new Claim(JwtClaimTypes.Name, username)); + } - if (!identity.HasClaim(x => x.Type == JwtClaimTypes.Name)) + if (_userManager.SupportsUserEmail) + { + var email = await _userManager.GetEmailAsync(user); + if (!string.IsNullOrWhiteSpace(email)) { - identity.AddIfNotContains(new Claim(JwtClaimTypes.Name, username)); + identity.AddIfNotContains(new Claim(JwtClaimTypes.Email, email)); + identity.AddIfNotContains(new Claim(JwtClaimTypes.EmailVerified, + await _userManager.IsEmailConfirmedAsync(user) ? "true" : "false", ClaimValueTypes.Boolean)); } + } - if (_userManager.SupportsUserEmail) + if (_userManager.SupportsUserPhoneNumber) + { + var phoneNumber = await _userManager.GetPhoneNumberAsync(user); + if (!string.IsNullOrWhiteSpace(phoneNumber)) { - var email = await _userManager.GetEmailAsync(user); - if (!string.IsNullOrWhiteSpace(email)) - { - identity.AddIfNotContains(new Claim(JwtClaimTypes.Email, email)); - identity.AddIfNotContains(new Claim(JwtClaimTypes.EmailVerified, - await _userManager.IsEmailConfirmedAsync(user) ? "true" : "false", ClaimValueTypes.Boolean)); - } + identity.AddIfNotContains(new Claim(JwtClaimTypes.PhoneNumber, phoneNumber)); + identity.AddIfNotContains(new Claim(JwtClaimTypes.PhoneNumberVerified, + await _userManager.IsPhoneNumberConfirmedAsync(user) ? "true" : "false", + ClaimValueTypes.Boolean)); } + } - if (_userManager.SupportsUserPhoneNumber) + if (user is IdentityUser identityUser) + { + if (!identityUser.Name.IsNullOrEmpty()) { - var phoneNumber = await _userManager.GetPhoneNumberAsync(user); - if (!string.IsNullOrWhiteSpace(phoneNumber)) - { - identity.AddIfNotContains(new Claim(JwtClaimTypes.PhoneNumber, phoneNumber)); - identity.AddIfNotContains(new Claim(JwtClaimTypes.PhoneNumberVerified, - await _userManager.IsPhoneNumberConfirmedAsync(user) ? "true" : "false", - ClaimValueTypes.Boolean)); - } + identity.AddIfNotContains(new Claim(JwtClaimTypes.GivenName, identityUser.Name)); } - if (user is IdentityUser identityUser) + if (!identityUser.Surname.IsNullOrEmpty()) { - if (!identityUser.Name.IsNullOrEmpty()) - { - identity.AddIfNotContains(new Claim(JwtClaimTypes.GivenName, identityUser.Name)); - } - - if (!identityUser.Surname.IsNullOrEmpty()) - { - identity.AddIfNotContains(new Claim(JwtClaimTypes.FamilyName, identityUser.Surname)); - } + identity.AddIfNotContains(new Claim(JwtClaimTypes.FamilyName, identityUser.Surname)); } - - return principal; } + + return principal; } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/SignInResultExtensions.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/SignInResultExtensions.cs index 6f167912c3..4693b7e779 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/SignInResultExtensions.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/SignInResultExtensions.cs @@ -1,37 +1,36 @@ using Microsoft.AspNetCore.Identity; -namespace Volo.Abp.IdentityServer.AspNetIdentity +namespace Volo.Abp.IdentityServer.AspNetIdentity; + +public static class SignInResultExtensions { - public static class SignInResultExtensions + public static string ToIdentitySecurityLogAction(this SignInResult result) { - public static string ToIdentitySecurityLogAction(this SignInResult result) + if (result.Succeeded) { - if (result.Succeeded) - { - return IdentityServerSecurityLogActionConsts.LoginSucceeded; - } - - if (result.IsLockedOut) - { - return IdentityServerSecurityLogActionConsts.LoginLockedout; - } + return IdentityServerSecurityLogActionConsts.LoginSucceeded; + } - if (result.RequiresTwoFactor) - { - return IdentityServerSecurityLogActionConsts.LoginRequiresTwoFactor; - } + if (result.IsLockedOut) + { + return IdentityServerSecurityLogActionConsts.LoginLockedout; + } - if (result.IsNotAllowed) - { - return IdentityServerSecurityLogActionConsts.LoginNotAllowed; - } + if (result.RequiresTwoFactor) + { + return IdentityServerSecurityLogActionConsts.LoginRequiresTwoFactor; + } - if (!result.Succeeded) - { - return IdentityServerSecurityLogActionConsts.LoginFailed; - } + if (result.IsNotAllowed) + { + return IdentityServerSecurityLogActionConsts.LoginNotAllowed; + } + if (!result.Succeeded) + { return IdentityServerSecurityLogActionConsts.LoginFailed; } + + return IdentityServerSecurityLogActionConsts.LoginFailed; } } 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 07f9eec153..675baf3ebf 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 @@ -6,340 +6,339 @@ using IdentityServer4.Models; using JetBrains.Annotations; using Volo.Abp.Domain.Entities.Auditing; -namespace Volo.Abp.IdentityServer.Clients +namespace Volo.Abp.IdentityServer.Clients; + +public class Client : FullAuditedAggregateRoot { - public class Client : FullAuditedAggregateRoot - { - public virtual string ClientId { get; set; } + public virtual string ClientId { get; set; } - public virtual string ClientName { get; set; } + public virtual string ClientName { get; set; } - public virtual string Description { get; set; } + public virtual string Description { get; set; } - public virtual string ClientUri { get; set; } + public virtual string ClientUri { get; set; } - public virtual string LogoUri { get; set; } + public virtual string LogoUri { get; set; } - public virtual bool Enabled { get; set; } = true; + public virtual bool Enabled { get; set; } = true; - public virtual string ProtocolType { get; set; } + public virtual string ProtocolType { get; set; } - public virtual bool RequireClientSecret { get; set; } + public virtual bool RequireClientSecret { get; set; } - public virtual bool RequireConsent { get; set; } + public virtual bool RequireConsent { get; set; } - public virtual bool AllowRememberConsent { get; set; } + public virtual bool AllowRememberConsent { get; set; } - public virtual bool AlwaysIncludeUserClaimsInIdToken { get; set; } + public virtual bool AlwaysIncludeUserClaimsInIdToken { get; set; } - public virtual bool RequirePkce { get; set; } + public virtual bool RequirePkce { get; set; } - public virtual bool AllowPlainTextPkce { get; set; } + public virtual bool AllowPlainTextPkce { get; set; } - public virtual bool RequireRequestObject { get; set; } + public virtual bool RequireRequestObject { get; set; } - public virtual bool AllowAccessTokensViaBrowser { get; set; } + public virtual bool AllowAccessTokensViaBrowser { get; set; } - public virtual string FrontChannelLogoutUri { get; set; } + public virtual string FrontChannelLogoutUri { get; set; } - public virtual bool FrontChannelLogoutSessionRequired { get; set; } + public virtual bool FrontChannelLogoutSessionRequired { get; set; } - public virtual string BackChannelLogoutUri { get; set; } + public virtual string BackChannelLogoutUri { get; set; } - public virtual bool BackChannelLogoutSessionRequired { get; set; } + public virtual bool BackChannelLogoutSessionRequired { get; set; } - public virtual bool AllowOfflineAccess { get; set; } + public virtual bool AllowOfflineAccess { get; set; } - public virtual int IdentityTokenLifetime { get; set; } + public virtual int IdentityTokenLifetime { get; set; } - public virtual string AllowedIdentityTokenSigningAlgorithms { get; set; } + public virtual string AllowedIdentityTokenSigningAlgorithms { get; set; } - public virtual int AccessTokenLifetime { get; set; } + public virtual int AccessTokenLifetime { get; set; } - public virtual int AuthorizationCodeLifetime { get; set; } + public virtual int AuthorizationCodeLifetime { get; set; } - public virtual int? ConsentLifetime { get; set; } + public virtual int? ConsentLifetime { get; set; } - public virtual int AbsoluteRefreshTokenLifetime { get; set; } + public virtual int AbsoluteRefreshTokenLifetime { get; set; } - public virtual int SlidingRefreshTokenLifetime { get; set; } + public virtual int SlidingRefreshTokenLifetime { get; set; } - public virtual int RefreshTokenUsage { get; set; } + public virtual int RefreshTokenUsage { get; set; } - public virtual bool UpdateAccessTokenClaimsOnRefresh { get; set; } + public virtual bool UpdateAccessTokenClaimsOnRefresh { get; set; } - public virtual int RefreshTokenExpiration { get; set; } + public virtual int RefreshTokenExpiration { get; set; } - public virtual int AccessTokenType { get; set; } + public virtual int AccessTokenType { get; set; } - public virtual bool EnableLocalLogin { get; set; } + public virtual bool EnableLocalLogin { get; set; } - public virtual bool IncludeJwtId { get; set; } + public virtual bool IncludeJwtId { get; set; } - public virtual bool AlwaysSendClientClaims { get; set; } + public virtual bool AlwaysSendClientClaims { get; set; } - public virtual string ClientClaimsPrefix { get; set; } + public virtual string ClientClaimsPrefix { get; set; } - public virtual string PairWiseSubjectSalt { get; set; } + public virtual string PairWiseSubjectSalt { get; set; } - public virtual int? UserSsoLifetime { get; set; } + public virtual int? UserSsoLifetime { get; set; } - public virtual string UserCodeType { get; set; } + public virtual string UserCodeType { get; set; } - public virtual int DeviceCodeLifetime { get; set; } = 300; + public virtual int DeviceCodeLifetime { get; set; } = 300; - public virtual List AllowedScopes { get; set; } + public virtual List AllowedScopes { get; set; } - public virtual List ClientSecrets { get; set; } + public virtual List ClientSecrets { get; set; } - public virtual List AllowedGrantTypes { get; set; } + public virtual List AllowedGrantTypes { get; set; } - public virtual List AllowedCorsOrigins { get; set; } + public virtual List AllowedCorsOrigins { get; set; } - public virtual List RedirectUris { get; set; } + public virtual List RedirectUris { get; set; } - public virtual List PostLogoutRedirectUris { get; set; } + public virtual List PostLogoutRedirectUris { get; set; } - public virtual List IdentityProviderRestrictions { get; set; } + public virtual List IdentityProviderRestrictions { get; set; } - public virtual List Claims { get; set; } + public virtual List Claims { get; set; } - public virtual List Properties { get; set; } + public virtual List Properties { get; set; } - protected Client() - { + protected Client() + { - } + } - public Client(Guid id, [NotNull] string clientId) - : base(id) - { - Check.NotNull(clientId, nameof(clientId)); - - ClientId = clientId; - - //TODO: Replace magics with constants? - - ProtocolType = IdentityServerConstants.ProtocolTypes.OpenIdConnect; - RequireClientSecret = true; - RequireConsent = false; - AllowRememberConsent = true; - RequirePkce = true; - FrontChannelLogoutSessionRequired = true; - BackChannelLogoutSessionRequired = true; - IdentityTokenLifetime = 300; - AccessTokenLifetime = 3600; - AuthorizationCodeLifetime = 300; - AbsoluteRefreshTokenLifetime = 2592000; - SlidingRefreshTokenLifetime = 1296000; - RefreshTokenUsage = (int)TokenUsage.OneTimeOnly; - RefreshTokenExpiration = (int)TokenExpiration.Absolute; - AccessTokenType = (int)IdentityServer4.Models.AccessTokenType.Jwt; - EnableLocalLogin = true; - ClientClaimsPrefix = "client_"; - - AllowedScopes = new List(); - ClientSecrets = new List(); - AllowedGrantTypes = new List(); - AllowedCorsOrigins = new List(); - RedirectUris = new List(); - PostLogoutRedirectUris = new List(); - IdentityProviderRestrictions = new List(); - Claims = new List(); - Properties = new List(); - } + public Client(Guid id, [NotNull] string clientId) + : base(id) + { + Check.NotNull(clientId, nameof(clientId)); + + ClientId = clientId; + + //TODO: Replace magics with constants? + + ProtocolType = IdentityServerConstants.ProtocolTypes.OpenIdConnect; + RequireClientSecret = true; + RequireConsent = false; + AllowRememberConsent = true; + RequirePkce = true; + FrontChannelLogoutSessionRequired = true; + BackChannelLogoutSessionRequired = true; + IdentityTokenLifetime = 300; + AccessTokenLifetime = 3600; + AuthorizationCodeLifetime = 300; + AbsoluteRefreshTokenLifetime = 2592000; + SlidingRefreshTokenLifetime = 1296000; + RefreshTokenUsage = (int)TokenUsage.OneTimeOnly; + RefreshTokenExpiration = (int)TokenExpiration.Absolute; + AccessTokenType = (int)IdentityServer4.Models.AccessTokenType.Jwt; + EnableLocalLogin = true; + ClientClaimsPrefix = "client_"; + + AllowedScopes = new List(); + ClientSecrets = new List(); + AllowedGrantTypes = new List(); + AllowedCorsOrigins = new List(); + RedirectUris = new List(); + PostLogoutRedirectUris = new List(); + IdentityProviderRestrictions = new List(); + Claims = new List(); + Properties = new List(); + } - public virtual void AddGrantType([NotNull] string grantType) - { - AllowedGrantTypes.Add(new ClientGrantType(Id, grantType)); - } + public virtual void AddGrantType([NotNull] string grantType) + { + AllowedGrantTypes.Add(new ClientGrantType(Id, grantType)); + } - public virtual void RemoveAllAllowedGrantTypes() - { - AllowedGrantTypes.Clear(); - } + public virtual void RemoveAllAllowedGrantTypes() + { + AllowedGrantTypes.Clear(); + } - public virtual void RemoveGrantType(string grantType) - { - AllowedGrantTypes.RemoveAll(r => r.GrantType == grantType); - } + public virtual void RemoveGrantType(string grantType) + { + AllowedGrantTypes.RemoveAll(r => r.GrantType == grantType); + } - public virtual ClientGrantType FindGrantType(string grantType) - { - return AllowedGrantTypes.FirstOrDefault(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) - { - ClientSecrets.Add(new ClientSecret(Id, value, expiration, type, description)); - } + public virtual void AddSecret([NotNull] string value, DateTime? expiration = null, string type = IdentityServerConstants.SecretTypes.SharedSecret, string description = null) + { + 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 RemoveSecret([NotNull] string value, string type = IdentityServerConstants.SecretTypes.SharedSecret) + { + ClientSecrets.RemoveAll(s => s.Value == value && s.Type == type); + } - public virtual ClientSecret FindSecret([NotNull] string value, string type = IdentityServerConstants.SecretTypes.SharedSecret) - { - return ClientSecrets.FirstOrDefault(s => s.Type == type && s.Value == value); - } + 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)); - } + public virtual void AddScope([NotNull] string scope) + { + AllowedScopes.Add(new ClientScope(Id, scope)); + } - public virtual void RemoveAllScopes() - { - AllowedScopes.Clear(); - } + public virtual void RemoveAllScopes() + { + AllowedScopes.Clear(); + } - public virtual void RemoveScope(string scope) - { - AllowedScopes.RemoveAll(r => r.Scope == scope); - } + 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 ClientScope FindScope(string scope) + { + return AllowedScopes.FirstOrDefault(r => r.Scope == scope); + } - public virtual void AddCorsOrigin([NotNull] string origin) - { - AllowedCorsOrigins.Add(new ClientCorsOrigin(Id, origin)); - } + public virtual void AddCorsOrigin([NotNull] string origin) + { + AllowedCorsOrigins.Add(new ClientCorsOrigin(Id, origin)); + } - public virtual void AddRedirectUri([NotNull] string redirectUri) - { - RedirectUris.Add(new ClientRedirectUri(Id, redirectUri)); - } + public virtual void AddRedirectUri([NotNull] string redirectUri) + { + RedirectUris.Add(new ClientRedirectUri(Id, redirectUri)); + } - public virtual void AddPostLogoutRedirectUri([NotNull] string postLogoutRedirectUri) - { - PostLogoutRedirectUris.Add(new ClientPostLogoutRedirectUri(Id, postLogoutRedirectUri)); - } + public virtual void AddPostLogoutRedirectUri([NotNull] string postLogoutRedirectUri) + { + PostLogoutRedirectUris.Add(new ClientPostLogoutRedirectUri(Id, postLogoutRedirectUri)); + } - public virtual void RemoveAllCorsOrigins() - { - AllowedCorsOrigins.Clear(); - } + public virtual void RemoveAllCorsOrigins() + { + AllowedCorsOrigins.Clear(); + } - public virtual void RemoveCorsOrigin(string uri) - { - AllowedCorsOrigins.RemoveAll(c => c.Origin == uri); - } + public virtual void RemoveCorsOrigin(string uri) + { + AllowedCorsOrigins.RemoveAll(c => c.Origin == uri); + } - public virtual void RemoveAllRedirectUris() - { - RedirectUris.Clear(); - } + public virtual void RemoveAllRedirectUris() + { + RedirectUris.Clear(); + } - public virtual void RemoveRedirectUri(string uri) - { - RedirectUris.RemoveAll(r => r.RedirectUri == uri); - } + public virtual void RemoveRedirectUri(string uri) + { + RedirectUris.RemoveAll(r => r.RedirectUri == uri); + } - public virtual void RemoveAllPostLogoutRedirectUris() - { - PostLogoutRedirectUris.Clear(); - } + public virtual void RemoveAllPostLogoutRedirectUris() + { + PostLogoutRedirectUris.Clear(); + } - public virtual void RemovePostLogoutRedirectUri(string uri) - { - PostLogoutRedirectUris.RemoveAll(p => p.PostLogoutRedirectUri == uri); - } + public virtual void RemovePostLogoutRedirectUri(string uri) + { + PostLogoutRedirectUris.RemoveAll(p => p.PostLogoutRedirectUri == uri); + } - public virtual ClientCorsOrigin FindCorsOrigin(string uri) - { - return AllowedCorsOrigins.FirstOrDefault(c => c.Origin == uri); - } + public virtual ClientCorsOrigin FindCorsOrigin(string uri) + { + return AllowedCorsOrigins.FirstOrDefault(c => c.Origin == uri); + } - public virtual ClientRedirectUri FindRedirectUri(string uri) - { - return RedirectUris.FirstOrDefault(r => r.RedirectUri == 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 ClientPostLogoutRedirectUri FindPostLogoutRedirectUri(string uri) + { + return PostLogoutRedirectUris.FirstOrDefault(p => p.PostLogoutRedirectUri == uri); + } - public virtual void AddProperty([NotNull] string key, [NotNull] string value) + public virtual void AddProperty([NotNull] string key, [NotNull] string value) + { + var property = FindProperty(key); + if (property == null) { - var property = FindProperty(key); - if (property == null) - { - Properties.Add(new ClientProperty(Id, key, value)); - } - else - { - property.Value = value; - } + Properties.Add(new ClientProperty(Id, key, value)); } - - public virtual void RemoveAllProperties() + else { - Properties.Clear(); + property.Value = value; } + } - public virtual void RemoveProperty(string key) - { - Properties.RemoveAll(c => c.Key == key); - } + public virtual void RemoveAllProperties() + { + Properties.Clear(); + } - public virtual ClientProperty FindProperty(string key) - { - return Properties.FirstOrDefault(c => c.Key == key); - } + public virtual void RemoveProperty(string key) + { + Properties.RemoveAll(c => c.Key == key); + } - public virtual void AddClaim([NotNull] string type, [NotNull] string value) - { - Claims.Add(new ClientClaim(Id, type, value)); - } + public virtual ClientProperty FindProperty(string key) + { + return Properties.FirstOrDefault(c => c.Key == key); + } - public virtual void RemoveAllClaims() - { - Claims.Clear(); - } + public virtual void AddClaim([NotNull] string type, [NotNull] string value) + { + Claims.Add(new ClientClaim(Id, type, value)); + } - public virtual void RemoveClaim(string type) - { - Claims.RemoveAll(c => c.Type == type); - } + public virtual void RemoveAllClaims() + { + Claims.Clear(); + } - public virtual void RemoveClaim(string type, string value) - { - Claims.RemoveAll(c => c.Type == type && c.Value == value); - } + public virtual void RemoveClaim(string type) + { + Claims.RemoveAll(c => c.Type == type); + } - public virtual List FindClaims(string type) - { - return Claims.Where(c => c.Type == type).ToList(); - } + public virtual void RemoveClaim(string type, string value) + { + Claims.RemoveAll(c => c.Type == type && c.Value == value); + } - public virtual ClientClaim FindClaim(string type, string value) - { - return Claims.FirstOrDefault(c => c.Type == type && c.Value == value); - } + public virtual List FindClaims(string type) + { + return Claims.Where(c => c.Type == type).ToList(); + } - public virtual void AddIdentityProviderRestriction([NotNull] string provider) - { - IdentityProviderRestrictions.Add(new ClientIdPRestriction(Id, provider)); - } + public virtual ClientClaim FindClaim(string type, string value) + { + return Claims.FirstOrDefault(c => c.Type == type && c.Value == value); + } - public virtual void RemoveAllIdentityProviderRestrictions() - { - IdentityProviderRestrictions.Clear(); - } + public virtual void AddIdentityProviderRestriction([NotNull] string provider) + { + IdentityProviderRestrictions.Add(new ClientIdPRestriction(Id, provider)); + } - public virtual void RemoveIdentityProviderRestriction(string provider) - { - IdentityProviderRestrictions.RemoveAll(r => r.Provider == provider); - } + public virtual void RemoveAllIdentityProviderRestrictions() + { + IdentityProviderRestrictions.Clear(); + } - public virtual ClientIdPRestriction FindIdentityProviderRestriction(string provider) - { - return IdentityProviderRestrictions.FirstOrDefault(r => r.Provider == provider); - } + 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); } } 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 6faf585ee0..0ecb83f7a9 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 @@ -2,38 +2,37 @@ using System; using JetBrains.Annotations; using Volo.Abp.Domain.Entities; -namespace Volo.Abp.IdentityServer.Clients +namespace Volo.Abp.IdentityServer.Clients; + +public class ClientClaim : Entity { - public class ClientClaim : Entity - { - public virtual Guid ClientId { get; set; } + public virtual Guid ClientId { get; set; } - public virtual string Type { get; set; } + public virtual string Type { get; set; } - public virtual string Value { get; set; } + public virtual string Value { get; set; } - protected ClientClaim() - { + protected ClientClaim() + { - } + } - protected internal ClientClaim(Guid clientId, [NotNull] string type, string value) - { - Check.NotNull(type, nameof(type)); + protected internal ClientClaim(Guid clientId, [NotNull] string type, string value) + { + Check.NotNull(type, nameof(type)); - ClientId = clientId; - Type = type; - Value = value; - } + ClientId = clientId; + Type = type; + Value = value; + } - public virtual bool Equals(Guid clientId, string type, string value) - { - return ClientId == clientId && Type == type && Value == value; - } + public virtual bool Equals(Guid clientId, string type, string value) + { + return ClientId == clientId && Type == type && Value == value; + } - public override object[] GetKeys() - { - return new object[] { ClientId, Type, Value }; - } + public override object[] GetKeys() + { + return new object[] { ClientId, Type, Value }; } } 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 73f4b47637..6009555df8 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 @@ -2,35 +2,34 @@ using JetBrains.Annotations; using Volo.Abp.Domain.Entities; -namespace Volo.Abp.IdentityServer.Clients +namespace Volo.Abp.IdentityServer.Clients; + +public class ClientCorsOrigin : Entity { - public class ClientCorsOrigin : Entity - { - public virtual Guid ClientId { get; protected set; } + public virtual Guid ClientId { get; protected set; } - public virtual string Origin { get; protected set; } + public virtual string Origin { get; protected set; } - protected ClientCorsOrigin() - { + protected ClientCorsOrigin() + { - } + } - public virtual bool Equals(Guid clientId, [NotNull] string uri) - { - return ClientId == clientId && Origin == uri; - } + public virtual bool Equals(Guid clientId, [NotNull] string uri) + { + return ClientId == clientId && Origin == uri; + } - protected internal ClientCorsOrigin(Guid clientId, [NotNull] string origin) - { - Check.NotNull(origin, nameof(origin)); + protected internal ClientCorsOrigin(Guid clientId, [NotNull] string origin) + { + Check.NotNull(origin, nameof(origin)); - ClientId = clientId; - Origin = origin; - } + ClientId = clientId; + Origin = origin; + } - public override object[] GetKeys() - { - return new object[] { ClientId, Origin }; - } + public override object[] GetKeys() + { + return new object[] { ClientId, Origin }; } -} \ No newline at end of file +} 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 696ae1cd46..3ebdf01f3d 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 @@ -2,35 +2,34 @@ using JetBrains.Annotations; using Volo.Abp.Domain.Entities; -namespace Volo.Abp.IdentityServer.Clients +namespace Volo.Abp.IdentityServer.Clients; + +public class ClientGrantType : Entity { - public class ClientGrantType : Entity - { - public virtual Guid ClientId { get; protected set; } + public virtual Guid ClientId { get; protected set; } - public virtual string GrantType { get; protected set; } + public virtual string GrantType { get; protected set; } - protected ClientGrantType() - { + protected ClientGrantType() + { - } + } - public virtual bool Equals(Guid clientId, [NotNull] string grantType) - { - return ClientId == clientId && GrantType == grantType; - } + 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)); + protected internal ClientGrantType(Guid clientId, [NotNull] string grantType) + { + Check.NotNull(grantType, nameof(grantType)); - ClientId = clientId; - GrantType = grantType; - } + ClientId = clientId; + GrantType = grantType; + } - public override object[] GetKeys() - { - return new object[] { ClientId, GrantType }; - } + public override object[] GetKeys() + { + return new object[] { ClientId, GrantType }; } -} \ No newline at end of file +} 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 aff16986c2..51dc7acdc8 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 @@ -2,35 +2,34 @@ using JetBrains.Annotations; using Volo.Abp.Domain.Entities; -namespace Volo.Abp.IdentityServer.Clients +namespace Volo.Abp.IdentityServer.Clients; + +public class ClientIdPRestriction : Entity { - public class ClientIdPRestriction : Entity - { - public virtual Guid ClientId { get; set; } + public virtual Guid ClientId { get; set; } - public virtual string Provider { get; set; } + public virtual string Provider { get; set; } - protected ClientIdPRestriction() - { + protected ClientIdPRestriction() + { - } + } - public virtual bool Equals(Guid clientId, [NotNull] string provider) - { - return ClientId == clientId && Provider == provider; - } + 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)); + protected internal ClientIdPRestriction(Guid clientId, [NotNull] string provider) + { + Check.NotNull(provider, nameof(provider)); - ClientId = clientId; - Provider = provider; - } + ClientId = clientId; + Provider = provider; + } - public override object[] GetKeys() - { - return new object[] { ClientId, Provider }; - } + public override object[] GetKeys() + { + return new object[] { ClientId, Provider }; } -} \ No newline at end of file +} 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 0e0ca17ae8..c12d408506 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 @@ -2,35 +2,34 @@ using JetBrains.Annotations; using Volo.Abp.Domain.Entities; -namespace Volo.Abp.IdentityServer.Clients +namespace Volo.Abp.IdentityServer.Clients; + +public class ClientPostLogoutRedirectUri : Entity { - public class ClientPostLogoutRedirectUri : Entity - { - public virtual Guid ClientId { get; protected set; } + public virtual Guid ClientId { get; protected set; } - public virtual string PostLogoutRedirectUri { get; protected set; } - - protected ClientPostLogoutRedirectUri() - { + public virtual string PostLogoutRedirectUri { get; protected set; } - } + protected ClientPostLogoutRedirectUri() + { + + } - public virtual bool Equals(Guid clientId, [NotNull] string uri) - { - return ClientId == clientId && PostLogoutRedirectUri == uri; - } + 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)); + protected internal ClientPostLogoutRedirectUri(Guid clientId, [NotNull] string postLogoutRedirectUri) + { + Check.NotNull(postLogoutRedirectUri, nameof(postLogoutRedirectUri)); - ClientId = clientId; - PostLogoutRedirectUri = postLogoutRedirectUri; - } + ClientId = clientId; + PostLogoutRedirectUri = postLogoutRedirectUri; + } - public override object[] GetKeys() - { - return new object[] { ClientId, PostLogoutRedirectUri }; - } + public override object[] GetKeys() + { + return new object[] { ClientId, PostLogoutRedirectUri }; } -} \ No newline at end of file +} 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 7347f1cc7c..51b94e4620 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 @@ -2,38 +2,37 @@ using JetBrains.Annotations; using Volo.Abp.Domain.Entities; -namespace Volo.Abp.IdentityServer.Clients +namespace Volo.Abp.IdentityServer.Clients; + +public class ClientProperty : Entity { - public class ClientProperty : Entity - { - public virtual Guid ClientId { get; set; } + public virtual Guid ClientId { get; set; } - public virtual string Key { get; set; } + public virtual string Key { get; set; } - public virtual string Value { get; set; } + public virtual string Value { get; set; } - protected ClientProperty() - { + protected ClientProperty() + { - } + } - public virtual bool Equals(Guid clientId, [NotNull] string key, [NotNull] string value) - { - return ClientId == clientId && Key == key && Value == value; - } + public virtual bool Equals(Guid clientId, [NotNull] string key, [NotNull] 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)); + protected internal ClientProperty(Guid clientId, [NotNull] string key, [NotNull] string value) + { + Check.NotNull(key, nameof(key)); - ClientId = clientId; - Key = key; - Value = value; - } + ClientId = clientId; + Key = key; + Value = value; + } - public override object[] GetKeys() - { - return new object[] { ClientId, Key }; - } + public override object[] GetKeys() + { + return new object[] { ClientId, 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 89d461b58b..b30aa54b76 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 @@ -2,35 +2,34 @@ using JetBrains.Annotations; using Volo.Abp.Domain.Entities; -namespace Volo.Abp.IdentityServer.Clients +namespace Volo.Abp.IdentityServer.Clients; + +public class ClientRedirectUri : Entity { - public class ClientRedirectUri : Entity - { - public virtual Guid ClientId { get; protected set; } + public virtual Guid ClientId { get; protected set; } - public virtual string RedirectUri { get; protected set; } + public virtual string RedirectUri { get; protected set; } - protected ClientRedirectUri() - { + protected ClientRedirectUri() + { - } + } - public virtual bool Equals(Guid clientId, [NotNull] string uri) - { - return ClientId == clientId && RedirectUri == uri; - } + 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)); + protected internal ClientRedirectUri(Guid clientId, [NotNull] string redirectUri) + { + Check.NotNull(redirectUri, nameof(redirectUri)); - ClientId = clientId; - RedirectUri = redirectUri; - } + ClientId = clientId; + RedirectUri = redirectUri; + } - public override object[] GetKeys() - { - return new object[] { ClientId, RedirectUri }; - } + public override object[] GetKeys() + { + return new object[] { ClientId, RedirectUri }; } -} \ No newline at end of file +} 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 f94de116bb..58e78ebd8d 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 @@ -2,33 +2,32 @@ using JetBrains.Annotations; using Volo.Abp.Domain.Entities; -namespace Volo.Abp.IdentityServer.Clients +namespace Volo.Abp.IdentityServer.Clients; + +public class ClientScope : Entity { - public class ClientScope : Entity - { - public virtual Guid ClientId { get; protected set; } + public virtual Guid ClientId { get; protected set; } - public virtual string Scope { get; protected set; } + public virtual string Scope { get; protected set; } - protected ClientScope() - { + protected ClientScope() + { - } + } - public virtual bool Equals(Guid clientId, [NotNull] string scope) - { - return ClientId == clientId && Scope == scope; - } + public virtual bool Equals(Guid clientId, [NotNull] string scope) + { + return ClientId == clientId && Scope == scope; + } - protected internal ClientScope(Guid clientId, string scope) - { - ClientId = clientId; - Scope = scope; - } + protected internal ClientScope(Guid clientId, string scope) + { + ClientId = clientId; + Scope = scope; + } - public override object[] GetKeys() - { - return new object[] { ClientId, Scope }; - } + public override object[] GetKeys() + { + return new object[] { ClientId, Scope }; } -} \ No newline at end of file +} 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 01ed5d6f24..a939cac2b5 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 @@ -2,40 +2,39 @@ using IdentityServer4; using JetBrains.Annotations; -namespace Volo.Abp.IdentityServer.Clients +namespace Volo.Abp.IdentityServer.Clients; + +public class ClientSecret : Secret { - public class ClientSecret : Secret - { - public virtual Guid ClientId { get; protected set; } + public virtual Guid ClientId { get; protected set; } - protected ClientSecret() - { + protected ClientSecret() + { - } + } - protected internal ClientSecret( - Guid clientId, - [NotNull] string value, - DateTime? expiration = null, - string type = IdentityServerConstants.SecretTypes.SharedSecret, - string description = null - ) : base( - value, - expiration, - type, - description) - { - ClientId = clientId; - } + protected internal ClientSecret( + Guid clientId, + [NotNull] string value, + DateTime? expiration = null, + string type = IdentityServerConstants.SecretTypes.SharedSecret, + string description = null + ) : base( + value, + expiration, + type, + description) + { + ClientId = clientId; + } - public virtual bool Equals(Guid clientId, [NotNull] string value, string type = IdentityServerConstants.SecretTypes.SharedSecret) - { - return ClientId == clientId && Value == value && Type == type; - } + 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 }; - } + 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/ClientStore.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientStore.cs index d882fdbc52..bf2c4b6ef3 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientStore.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientStore.cs @@ -6,45 +6,44 @@ using Microsoft.Extensions.Options; using Volo.Abp.Caching; using Volo.Abp.ObjectMapping; -namespace Volo.Abp.IdentityServer.Clients +namespace Volo.Abp.IdentityServer.Clients; + +public class ClientStore : IClientStore { - public class ClientStore : IClientStore - { - protected IClientRepository ClientRepository { get; } - protected IObjectMapper ObjectMapper { get; } - protected IDistributedCache Cache { get; } - protected IdentityServerOptions Options { get; } + protected IClientRepository ClientRepository { get; } + protected IObjectMapper ObjectMapper { get; } + protected IDistributedCache Cache { get; } + protected IdentityServerOptions Options { get; } - public ClientStore( - IClientRepository clientRepository, - IObjectMapper objectMapper, - IDistributedCache cache, - IOptions options) - { - ClientRepository = clientRepository; - ObjectMapper = objectMapper; - Cache = cache; - Options = options.Value; - } + public ClientStore( + IClientRepository clientRepository, + IObjectMapper objectMapper, + IDistributedCache cache, + IOptions options) + { + ClientRepository = clientRepository; + ObjectMapper = objectMapper; + Cache = cache; + Options = options.Value; + } - public virtual async Task FindClientByIdAsync(string clientId) - { - return await GetCacheItemAsync(clientId); - } + public virtual async Task FindClientByIdAsync(string clientId) + { + return await GetCacheItemAsync(clientId); + } - protected virtual async Task GetCacheItemAsync(string clientId) - { - return await Cache.GetOrAddAsync(clientId, async () => - { - var client = await ClientRepository.FindByClientIdAsync(clientId); - return ObjectMapper.Map(client); - }, - optionsFactory: () => new DistributedCacheEntryOptions() - { - AbsoluteExpirationRelativeToNow = Options.Caching.ClientStoreExpiration - }, - considerUow: true); + protected virtual async Task GetCacheItemAsync(string clientId) + { + return await Cache.GetOrAddAsync(clientId, async () => + { + var client = await ClientRepository.FindByClientIdAsync(clientId); + return ObjectMapper.Map(client); + }, + optionsFactory: () => new DistributedCacheEntryOptions() + { + AbsoluteExpirationRelativeToNow = Options.Caching.ClientStoreExpiration + }, + considerUow: true); - } } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/IClientRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/IClientRepository.cs index 55d15a8c83..478ca592e0 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/IClientRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/IClientRepository.cs @@ -5,36 +5,35 @@ using System.Threading.Tasks; using JetBrains.Annotations; using Volo.Abp.Domain.Repositories; -namespace Volo.Abp.IdentityServer.Clients +namespace Volo.Abp.IdentityServer.Clients; + +public interface IClientRepository : IBasicRepository { - public interface IClientRepository : IBasicRepository - { - Task FindByClientIdAsync( - [NotNull] string clientId, - bool includeDetails = true, - CancellationToken cancellationToken = default - ); + Task FindByClientIdAsync( + [NotNull] string clientId, + bool includeDetails = true, + CancellationToken cancellationToken = default + ); - Task> GetListAsync( - string sorting, - int skipCount, - int maxResultCount, - string filter = null, - bool includeDetails = false, - CancellationToken cancellationToken = default - ); + Task> GetListAsync( + string sorting, + int skipCount, + int maxResultCount, + string filter = null, + bool includeDetails = false, + CancellationToken cancellationToken = default + ); - Task GetCountAsync( - string filter = null, - CancellationToken cancellationToken = default - ); + Task GetCountAsync( + string filter = null, + CancellationToken cancellationToken = default + ); - Task> GetAllDistinctAllowedCorsOriginsAsync(CancellationToken cancellationToken = default); + Task> GetAllDistinctAllowedCorsOriginsAsync(CancellationToken cancellationToken = default); - Task CheckClientIdExistAsync( - string clientId, - Guid? expectedId = null, - CancellationToken cancellationToken = default - ); - } + Task CheckClientIdExistAsync( + string clientId, + Guid? expectedId = null, + CancellationToken cancellationToken = default + ); } 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 c24452a08b..c0cc61791f 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 @@ -1,35 +1,34 @@ using System; using Volo.Abp.Domain.Entities.Auditing; -namespace Volo.Abp.IdentityServer.Devices +namespace Volo.Abp.IdentityServer.Devices; + +public class DeviceFlowCodes : CreationAuditedAggregateRoot { - public class DeviceFlowCodes : CreationAuditedAggregateRoot - { - public virtual string DeviceCode { get; set; } + public virtual string DeviceCode { get; set; } - public virtual string UserCode { get; set; } + public virtual string UserCode { get; set; } - public virtual string SubjectId { get; set; } + public virtual string SubjectId { get; set; } - public virtual string SessionId { get; set; } + public virtual string SessionId { get; set; } - public virtual string ClientId { get; set; } + public virtual string ClientId { get; set; } - public virtual string Description { get; set; } + public virtual string Description { get; set; } - public virtual DateTime? Expiration { get; set; } + public virtual DateTime? Expiration { get; set; } - public virtual string Data { get; set; } + public virtual string Data { get; set; } - protected DeviceFlowCodes() - { + protected DeviceFlowCodes() + { - } + } - public DeviceFlowCodes(Guid id) - : base(id) - { + public DeviceFlowCodes(Guid id) + : base(id) + { - } } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Devices/DeviceFlowStore.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Devices/DeviceFlowStore.cs index 90c9b9b9e6..e86bdad16b 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Devices/DeviceFlowStore.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Devices/DeviceFlowStore.cs @@ -7,136 +7,135 @@ using IdentityServer4.Stores.Serialization; using JetBrains.Annotations; using Volo.Abp.Guids; -namespace Volo.Abp.IdentityServer.Devices +namespace Volo.Abp.IdentityServer.Devices; + +public class DeviceFlowStore : IDeviceFlowStore { - public class DeviceFlowStore : IDeviceFlowStore + protected IDeviceFlowCodesRepository DeviceFlowCodesRepository { get; } + protected IGuidGenerator GuidGenerator { get; } + protected IPersistentGrantSerializer PersistentGrantSerializer { get; } + + public DeviceFlowStore( + IDeviceFlowCodesRepository deviceFlowCodesRepository, + IGuidGenerator guidGenerator, + IPersistentGrantSerializer persistentGrantSerializer) { - protected IDeviceFlowCodesRepository DeviceFlowCodesRepository { get; } - protected IGuidGenerator GuidGenerator { get; } - protected IPersistentGrantSerializer PersistentGrantSerializer { get; } - - public DeviceFlowStore( - IDeviceFlowCodesRepository deviceFlowCodesRepository, - IGuidGenerator guidGenerator, - IPersistentGrantSerializer persistentGrantSerializer) - { - DeviceFlowCodesRepository = deviceFlowCodesRepository; - GuidGenerator = guidGenerator; - PersistentGrantSerializer = persistentGrantSerializer; - } - - public virtual async Task StoreDeviceAuthorizationAsync(string deviceCode, string userCode, DeviceCode data) - { - Check.NotNull(deviceCode, nameof(deviceCode)); - Check.NotNull(userCode, nameof(userCode)); - Check.NotNull(data, nameof(data)); - - await DeviceFlowCodesRepository - .InsertAsync( - new DeviceFlowCodes(GuidGenerator.Create()) - { - DeviceCode = deviceCode, - UserCode = userCode, - ClientId = data.ClientId, - SubjectId = data.Subject?.FindFirst(JwtClaimTypes.Subject)?.Value, - CreationTime = data.CreationTime, - Expiration = data.CreationTime.AddSeconds(data.Lifetime), - Data = Serialize(data) - } - ); - } - - public virtual async Task FindByUserCodeAsync(string userCode) - { - Check.NotNull(userCode, nameof(userCode)); + DeviceFlowCodesRepository = deviceFlowCodesRepository; + GuidGenerator = guidGenerator; + PersistentGrantSerializer = persistentGrantSerializer; + } - var deviceCodes = await DeviceFlowCodesRepository - .FindByUserCodeAsync(userCode) - ; + public virtual async Task StoreDeviceAuthorizationAsync(string deviceCode, string userCode, DeviceCode data) + { + Check.NotNull(deviceCode, nameof(deviceCode)); + Check.NotNull(userCode, nameof(userCode)); + Check.NotNull(data, nameof(data)); + + await DeviceFlowCodesRepository + .InsertAsync( + new DeviceFlowCodes(GuidGenerator.Create()) + { + DeviceCode = deviceCode, + UserCode = userCode, + ClientId = data.ClientId, + SubjectId = data.Subject?.FindFirst(JwtClaimTypes.Subject)?.Value, + CreationTime = data.CreationTime, + Expiration = data.CreationTime.AddSeconds(data.Lifetime), + Data = Serialize(data) + } + ); + } - if (deviceCodes == null) - { - return null; - } + public virtual async Task FindByUserCodeAsync(string userCode) + { + Check.NotNull(userCode, nameof(userCode)); - return DeserializeToDeviceCode(deviceCodes.Data); - } + var deviceCodes = await DeviceFlowCodesRepository + .FindByUserCodeAsync(userCode) + ; - public virtual async Task FindByDeviceCodeAsync(string deviceCode) + if (deviceCodes == null) { - Check.NotNull(deviceCode, nameof(deviceCode)); + return null; + } - var deviceCodes = await DeviceFlowCodesRepository - .FindByDeviceCodeAsync(deviceCode) - ; + return DeserializeToDeviceCode(deviceCodes.Data); + } - if (deviceCodes == null) - { - return null; - } + public virtual async Task FindByDeviceCodeAsync(string deviceCode) + { + Check.NotNull(deviceCode, nameof(deviceCode)); - return DeserializeToDeviceCode(deviceCodes.Data); - } + var deviceCodes = await DeviceFlowCodesRepository + .FindByDeviceCodeAsync(deviceCode) + ; - public virtual async Task UpdateByUserCodeAsync(string userCode, DeviceCode data) + if (deviceCodes == null) { - Check.NotNull(userCode, nameof(userCode)); - Check.NotNull(data, nameof(data)); + return null; + } + return DeserializeToDeviceCode(deviceCodes.Data); + } - var deviceCodes = await DeviceFlowCodesRepository - .FindByUserCodeAsync(userCode) - ; + public virtual async Task UpdateByUserCodeAsync(string userCode, DeviceCode data) + { + Check.NotNull(userCode, nameof(userCode)); + Check.NotNull(data, nameof(data)); - if (deviceCodes == null) - { - throw new InvalidOperationException($"Could not update device code by the given userCode: {userCode}"); - } - deviceCodes.SubjectId = data.Subject?.FindFirst(JwtClaimTypes.Subject)?.Value; - deviceCodes.Data = Serialize(data); + var deviceCodes = await DeviceFlowCodesRepository + .FindByUserCodeAsync(userCode) + ; - await DeviceFlowCodesRepository - .UpdateAsync(deviceCodes, autoSave: true) - ; + if (deviceCodes == null) + { + throw new InvalidOperationException($"Could not update device code by the given userCode: {userCode}"); } - public virtual async Task RemoveByDeviceCodeAsync(string deviceCode) - { - Check.NotNull(deviceCode, nameof(deviceCode)); + deviceCodes.SubjectId = data.Subject?.FindFirst(JwtClaimTypes.Subject)?.Value; + deviceCodes.Data = Serialize(data); - var deviceCodes = await DeviceFlowCodesRepository - .FindByDeviceCodeAsync(deviceCode) - ; + await DeviceFlowCodesRepository + .UpdateAsync(deviceCodes, autoSave: true) + ; + } - if (deviceCodes == null) - { - return; - } + public virtual async Task RemoveByDeviceCodeAsync(string deviceCode) + { + Check.NotNull(deviceCode, nameof(deviceCode)); - await DeviceFlowCodesRepository - .DeleteAsync(deviceCodes, autoSave: true) - ; - } + var deviceCodes = await DeviceFlowCodesRepository + .FindByDeviceCodeAsync(deviceCode) + ; - protected virtual string Serialize([CanBeNull] DeviceCode deviceCode) + if (deviceCodes == null) { - if (deviceCode == null) - { - return null; - } - - return PersistentGrantSerializer.Serialize(deviceCode); + return; } - protected virtual DeviceCode DeserializeToDeviceCode([CanBeNull] string data) + await DeviceFlowCodesRepository + .DeleteAsync(deviceCodes, autoSave: true) + ; + } + + protected virtual string Serialize([CanBeNull] DeviceCode deviceCode) + { + if (deviceCode == null) { - if (data == null) - { - return null; - } + return null; + } + + return PersistentGrantSerializer.Serialize(deviceCode); + } - return PersistentGrantSerializer.Deserialize(data); + protected virtual DeviceCode DeserializeToDeviceCode([CanBeNull] string data) + { + if (data == null) + { + return null; } + + return PersistentGrantSerializer.Deserialize(data); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Devices/IDeviceFlowCodesRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Devices/IDeviceFlowCodesRepository.cs index b6bcb69bed..64f66fd6fe 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Devices/IDeviceFlowCodesRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Devices/IDeviceFlowCodesRepository.cs @@ -4,24 +4,23 @@ using System.Threading; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories; -namespace Volo.Abp.IdentityServer.Devices +namespace Volo.Abp.IdentityServer.Devices; + +public interface IDeviceFlowCodesRepository : IBasicRepository { - public interface IDeviceFlowCodesRepository : IBasicRepository - { - Task FindByUserCodeAsync( - string userCode, - CancellationToken cancellationToken = default - ); + Task FindByUserCodeAsync( + string userCode, + CancellationToken cancellationToken = default + ); - Task FindByDeviceCodeAsync( - string deviceCode, - CancellationToken cancellationToken = default - ); + Task FindByDeviceCodeAsync( + string deviceCode, + CancellationToken cancellationToken = default + ); - Task> GetListByExpirationAsync( - DateTime maxExpirationDate, - int maxResultCount, - CancellationToken cancellationToken = default - ); - } + Task> GetListByExpirationAsync( + DateTime maxExpirationDate, + int maxResultCount, + CancellationToken cancellationToken = default + ); } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/IPersistentGrantRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/IPersistentGrantRepository.cs index 6642440234..466ad987b5 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/IPersistentGrantRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/IPersistentGrantRepository.cs @@ -4,38 +4,37 @@ using System.Threading; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories; -namespace Volo.Abp.IdentityServer.Grants +namespace Volo.Abp.IdentityServer.Grants; + +public interface IPersistentGrantRepository : IBasicRepository { - public interface IPersistentGrantRepository : IBasicRepository - { - Task> GetListAsync( - string subjectId, - string sessionId, - string clientId, - string type, bool includeDetails = false, CancellationToken cancellationToken = default); + Task> GetListAsync( + string subjectId, + string sessionId, + string clientId, + string type, bool includeDetails = false, CancellationToken cancellationToken = default); - Task FindByKeyAsync( - string key, - CancellationToken cancellationToken = default - ); + Task FindByKeyAsync( + string key, + CancellationToken cancellationToken = default + ); - Task> GetListBySubjectIdAsync( - string key, - CancellationToken cancellationToken = default - ); + Task> GetListBySubjectIdAsync( + string key, + CancellationToken cancellationToken = default + ); - Task> GetListByExpirationAsync( - DateTime maxExpirationDate, - int maxResultCount, - CancellationToken cancellationToken = default - ); + Task> GetListByExpirationAsync( + DateTime maxExpirationDate, + int maxResultCount, + CancellationToken cancellationToken = default + ); - Task DeleteAsync( - string subjectId = null, - string sessionId = null, - string clientId = null, - string type = null, - CancellationToken cancellationToken = default - ); - } + Task DeleteAsync( + string subjectId = null, + string sessionId = null, + string clientId = null, + string type = null, + CancellationToken cancellationToken = default + ); } 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 907e2cbff8..ee003d6bcc 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,37 +1,36 @@ using System; using Volo.Abp.Domain.Entities; -namespace Volo.Abp.IdentityServer.Grants +namespace Volo.Abp.IdentityServer.Grants; + +public class PersistedGrant : AggregateRoot { - public class PersistedGrant : AggregateRoot - { - public virtual string Key { get; set; } + public virtual string Key { get; set; } - public virtual string Type { get; set; } + public virtual string Type { get; set; } - public virtual string SubjectId { get; set; } + public virtual string SubjectId { get; set; } - public virtual string SessionId { get; set; } + public virtual string SessionId { get; set; } - public virtual string ClientId { get; set; } + public virtual string ClientId { get; set; } - public virtual string Description { get; set; } + public virtual string Description { get; set; } - public virtual DateTime CreationTime { get; set; } + public virtual DateTime CreationTime { get; set; } - public virtual DateTime? Expiration { get; set; } + public virtual DateTime? Expiration { get; set; } - public virtual DateTime? ConsumedTime { get; set; } + public virtual DateTime? ConsumedTime { get; set; } - public virtual string Data { get; set; } + public virtual string Data { get; set; } - protected PersistedGrant() - { - } + protected PersistedGrant() + { + } - public PersistedGrant(Guid id) - : base(id) - { - } + public PersistedGrant(Guid id) + : base(id) + { } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrantStore.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrantStore.cs index 19efb54a56..555991bab4 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrantStore.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrantStore.cs @@ -6,64 +6,63 @@ using Volo.Abp.Domain.Entities; using Volo.Abp.Guids; using Volo.Abp.ObjectMapping; -namespace Volo.Abp.IdentityServer.Grants +namespace Volo.Abp.IdentityServer.Grants; + +public class PersistedGrantStore : IPersistedGrantStore { - public class PersistedGrantStore : IPersistedGrantStore + protected IPersistentGrantRepository PersistentGrantRepository { get; } + protected IObjectMapper ObjectMapper { get; } + protected IGuidGenerator GuidGenerator { get; } + + public PersistedGrantStore(IPersistentGrantRepository persistentGrantRepository, + IObjectMapper objectMapper, IGuidGenerator guidGenerator) { - protected IPersistentGrantRepository PersistentGrantRepository { get; } - protected IObjectMapper ObjectMapper { get; } - protected IGuidGenerator GuidGenerator { get; } + PersistentGrantRepository = persistentGrantRepository; + ObjectMapper = objectMapper; + GuidGenerator = guidGenerator; + } - public PersistedGrantStore(IPersistentGrantRepository persistentGrantRepository, - IObjectMapper objectMapper, IGuidGenerator guidGenerator) + public virtual async Task StoreAsync(IdentityServer4.Models.PersistedGrant grant) + { + var entity = await PersistentGrantRepository.FindByKeyAsync(grant.Key); + if (entity == null) { - PersistentGrantRepository = persistentGrantRepository; - ObjectMapper = objectMapper; - GuidGenerator = guidGenerator; + entity = ObjectMapper.Map(grant); + EntityHelper.TrySetId(entity, () => GuidGenerator.Create()); + await PersistentGrantRepository.InsertAsync(entity); } - - public virtual async Task StoreAsync(IdentityServer4.Models.PersistedGrant grant) + else { - var entity = await PersistentGrantRepository.FindByKeyAsync(grant.Key); - if (entity == null) - { - entity = ObjectMapper.Map(grant); - EntityHelper.TrySetId(entity, () => GuidGenerator.Create()); - await PersistentGrantRepository.InsertAsync(entity); - } - else - { - ObjectMapper.Map(grant, entity); - await PersistentGrantRepository.UpdateAsync(entity); - } + ObjectMapper.Map(grant, entity); + await PersistentGrantRepository.UpdateAsync(entity); } + } - public virtual async Task GetAsync(string key) - { - var persistedGrant = await PersistentGrantRepository.FindByKeyAsync(key); - return ObjectMapper.Map(persistedGrant); - } + public virtual async Task GetAsync(string key) + { + var persistedGrant = await PersistentGrantRepository.FindByKeyAsync(key); + return ObjectMapper.Map(persistedGrant); + } - public virtual async Task> GetAllAsync(PersistedGrantFilter filter) - { - var persistedGrants = await PersistentGrantRepository.GetListAsync(filter.SubjectId, filter.SessionId, filter.ClientId, filter.Type); - return ObjectMapper.Map, List>(persistedGrants); - } + public virtual async Task> GetAllAsync(PersistedGrantFilter filter) + { + var persistedGrants = await PersistentGrantRepository.GetListAsync(filter.SubjectId, filter.SessionId, filter.ClientId, filter.Type); + return ObjectMapper.Map, List>(persistedGrants); + } - public virtual async Task RemoveAsync(string key) + public virtual async Task RemoveAsync(string key) + { + var persistedGrant = await PersistentGrantRepository.FindByKeyAsync(key); + if (persistedGrant == null) { - var persistedGrant = await PersistentGrantRepository.FindByKeyAsync(key); - if (persistedGrant == null) - { - return; - } - - await PersistentGrantRepository.DeleteAsync(persistedGrant); + return; } - public virtual async Task RemoveAllAsync(PersistedGrantFilter filter) - { - await PersistentGrantRepository.DeleteAsync(filter.SubjectId, filter.SessionId, filter.ClientId, filter.Type); - } + await PersistentGrantRepository.DeleteAsync(persistedGrant); + } + + public virtual async Task RemoveAllAsync(PersistedGrantFilter filter) + { + await PersistentGrantRepository.DeleteAsync(filter.SubjectId, filter.SessionId, filter.ClientId, filter.Type); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceDataSeeder.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceDataSeeder.cs index cd50765ec5..86f51070b9 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceDataSeeder.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceDataSeeder.cs @@ -1,9 +1,8 @@ using System.Threading.Tasks; -namespace Volo.Abp.IdentityServer.IdentityResources +namespace Volo.Abp.IdentityServer.IdentityResources; + +public interface IIdentityResourceDataSeeder { - public interface IIdentityResourceDataSeeder - { - Task CreateStandardResourcesAsync(); - } -} \ No newline at end of file + Task CreateStandardResourcesAsync(); +} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceRepository.cs index 0ddf31e58e..4a9050ca55 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceRepository.cs @@ -4,40 +4,39 @@ using System.Threading; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories; -namespace Volo.Abp.IdentityServer.IdentityResources +namespace Volo.Abp.IdentityServer.IdentityResources; + +public interface IIdentityResourceRepository : IBasicRepository { - public interface IIdentityResourceRepository : IBasicRepository - { - Task> GetListByScopeNameAsync( - string[] scopeNames, - bool includeDetails = false, - CancellationToken cancellationToken = default - ); + Task> GetListByScopeNameAsync( + string[] scopeNames, + bool includeDetails = false, + CancellationToken cancellationToken = default + ); - Task> GetListAsync( - string sorting, - int skipCount, - int maxResultCount, - string filter = null, - bool includeDetails = false, - CancellationToken cancellationToken = default - ); + Task> GetListAsync( + string sorting, + int skipCount, + int maxResultCount, + string filter = null, + bool includeDetails = false, + CancellationToken cancellationToken = default + ); - Task GetCountAsync( - string filter = null, - CancellationToken cancellationToken = default - ); + Task GetCountAsync( + string filter = null, + CancellationToken cancellationToken = default + ); - Task FindByNameAsync( - string name, - bool includeDetails = true, - CancellationToken cancellationToken = default - ); + Task FindByNameAsync( + string name, + bool includeDetails = true, + CancellationToken cancellationToken = default + ); - Task CheckNameExistAsync( - string name, - Guid? expectedId = null, - CancellationToken cancellationToken = default - ); - } + Task CheckNameExistAsync( + string name, + Guid? expectedId = null, + CancellationToken cancellationToken = default + ); } 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 4b8782b455..e4286bf06a 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 @@ -4,118 +4,117 @@ using System.Linq; using JetBrains.Annotations; using Volo.Abp.Domain.Entities.Auditing; -namespace Volo.Abp.IdentityServer.IdentityResources +namespace Volo.Abp.IdentityServer.IdentityResources; + +public class IdentityResource : FullAuditedAggregateRoot { - public class IdentityResource : FullAuditedAggregateRoot - { - public virtual string Name { get; set; } + public virtual string Name { get; set; } - public virtual string DisplayName { get; set; } + public virtual string DisplayName { get; set; } - public virtual string Description { get; set; } + public virtual string Description { get; set; } - public virtual bool Enabled { get; set; } + public virtual bool Enabled { get; set; } - public virtual bool Required { get; set; } + public virtual bool Required { get; set; } - public virtual bool Emphasize { get; set; } + public virtual bool Emphasize { get; set; } - public virtual bool ShowInDiscoveryDocument { get; set; } + public virtual bool ShowInDiscoveryDocument { get; set; } - public virtual List UserClaims { get; set; } + public virtual List UserClaims { get; set; } - public virtual List Properties { get; set; } + public virtual List Properties { get; set; } - protected IdentityResource() - { + protected IdentityResource() + { - } + } - public IdentityResource( - Guid id, - [NotNull] string name, - string displayName = null, - string description = null, - bool enabled = true, - bool required = false, - bool emphasize = false, - bool showInDiscoveryDocument = true - ) : base(id) - { - Check.NotNull(name, nameof(name)); - - Name = name; - DisplayName = displayName; - Description = description; - Enabled = enabled; - Required = required; - Emphasize = emphasize; - ShowInDiscoveryDocument = showInDiscoveryDocument; - - UserClaims = new List(); - Properties = new List(); - } + public IdentityResource( + Guid id, + [NotNull] string name, + string displayName = null, + string description = null, + bool enabled = true, + bool required = false, + bool emphasize = false, + bool showInDiscoveryDocument = true + ) : base(id) + { + Check.NotNull(name, nameof(name)); + + Name = name; + DisplayName = displayName; + Description = description; + Enabled = enabled; + Required = required; + Emphasize = emphasize; + ShowInDiscoveryDocument = showInDiscoveryDocument; + + UserClaims = new List(); + Properties = new List(); + } - public IdentityResource(Guid id, IdentityServer4.Models.IdentityResource resource) - : base(id) - { - Name = resource.Name; - DisplayName = resource.DisplayName; - Description = resource.Description; - Enabled = resource.Enabled; - Required = resource.Required; - Emphasize = resource.Emphasize; - ShowInDiscoveryDocument = resource.ShowInDiscoveryDocument; - UserClaims = resource.UserClaims.Select(claimType => new IdentityResourceClaim(id, claimType)).ToList(); - Properties = resource.Properties.Select(x => new IdentityResourceProperty(Id, x.Key, x.Value)).ToList(); - } + public IdentityResource(Guid id, IdentityServer4.Models.IdentityResource resource) + : base(id) + { + Name = resource.Name; + DisplayName = resource.DisplayName; + Description = resource.Description; + Enabled = resource.Enabled; + Required = resource.Required; + Emphasize = resource.Emphasize; + ShowInDiscoveryDocument = resource.ShowInDiscoveryDocument; + 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 IdentityResourceClaim(Id, type)); - } + public virtual void AddUserClaim([NotNull] string type) + { + UserClaims.Add(new IdentityResourceClaim(Id, type)); + } - public virtual void RemoveAllUserClaims() - { - UserClaims.Clear(); - } + public virtual void RemoveAllUserClaims() + { + UserClaims.Clear(); + } - public virtual void RemoveUserClaim(string type) - { - UserClaims.RemoveAll(c => c.Type == type); - } + public virtual void RemoveUserClaim(string type) + { + UserClaims.RemoveAll(c => c.Type == type); + } - public virtual IdentityResourceClaim FindUserClaim(string type) - { - return UserClaims.FirstOrDefault(c => c.Type == type); - } + public virtual IdentityResourceClaim FindUserClaim(string type) + { + return UserClaims.FirstOrDefault(c => c.Type == type); + } - public virtual void AddProperty([NotNull] string key, string value) + public virtual void AddProperty([NotNull] string key, string value) + { + var property = FindProperty(key); + if (property == null) { - var property = FindProperty(key); - if (property == null) - { - Properties.Add(new IdentityResourceProperty(Id, key, value)); - } - else - { - property.Value = value; - } + Properties.Add(new IdentityResourceProperty(Id, key, value)); } - - public virtual void RemoveAllProperties() + else { - Properties.Clear(); + property.Value = value; } + } - public virtual void RemoveProperty(string key) - { - Properties.RemoveAll(r => r.Key == key); - } + public virtual void RemoveAllProperties() + { + Properties.Clear(); + } - public virtual IdentityResourceProperty FindProperty(string key) - { - return Properties.FirstOrDefault(r => r.Key == key); - } + public virtual void RemoveProperty(string key) + { + Properties.RemoveAll(r => r.Key == key); + } + + public virtual IdentityResourceProperty FindProperty(string key) + { + return Properties.FirstOrDefault(r => r.Key == key); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceClaim.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceClaim.cs index 2bce3f66cf..51c7416904 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceClaim.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceClaim.cs @@ -1,31 +1,30 @@ using System; using JetBrains.Annotations; -namespace Volo.Abp.IdentityServer.IdentityResources +namespace Volo.Abp.IdentityServer.IdentityResources; + +public class IdentityResourceClaim : UserClaim { - public class IdentityResourceClaim : UserClaim - { - public virtual Guid IdentityResourceId { get; set; } + public virtual Guid IdentityResourceId { get; set; } - protected IdentityResourceClaim() - { + protected IdentityResourceClaim() + { - } + } - public virtual bool Equals(Guid identityResourceId, [NotNull] string type) - { - return IdentityResourceId == identityResourceId && Type == type; - } + public virtual bool Equals(Guid identityResourceId, [NotNull] string type) + { + return IdentityResourceId == identityResourceId && Type == type; + } - protected internal IdentityResourceClaim(Guid identityResourceId, [NotNull] string type) - : base(type) - { - IdentityResourceId = identityResourceId; - } + protected internal IdentityResourceClaim(Guid identityResourceId, [NotNull] string type) + : base(type) + { + IdentityResourceId = identityResourceId; + } - public override object[] GetKeys() - { - return new object[] { IdentityResourceId, Type }; - } + public override object[] GetKeys() + { + return new object[] { IdentityResourceId, Type }; } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceDataSeeder.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceDataSeeder.cs index 024f8bea13..64841227c9 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceDataSeeder.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceDataSeeder.cs @@ -3,28 +3,28 @@ using Volo.Abp.DependencyInjection; using Volo.Abp.Guids; using Volo.Abp.Identity; -namespace Volo.Abp.IdentityServer.IdentityResources +namespace Volo.Abp.IdentityServer.IdentityResources; + +public class IdentityResourceDataSeeder : IIdentityResourceDataSeeder, ITransientDependency { - public class IdentityResourceDataSeeder : IIdentityResourceDataSeeder, ITransientDependency - { - protected IIdentityClaimTypeRepository ClaimTypeRepository { get; } - protected IIdentityResourceRepository IdentityResourceRepository { get; } - protected IGuidGenerator GuidGenerator { get; } + protected IIdentityClaimTypeRepository ClaimTypeRepository { get; } + protected IIdentityResourceRepository IdentityResourceRepository { get; } + protected IGuidGenerator GuidGenerator { get; } - public IdentityResourceDataSeeder( - IIdentityResourceRepository identityResourceRepository, - IGuidGenerator guidGenerator, - IIdentityClaimTypeRepository claimTypeRepository) - { - IdentityResourceRepository = identityResourceRepository; - GuidGenerator = guidGenerator; - ClaimTypeRepository = claimTypeRepository; - } + public IdentityResourceDataSeeder( + IIdentityResourceRepository identityResourceRepository, + IGuidGenerator guidGenerator, + IIdentityClaimTypeRepository claimTypeRepository) + { + IdentityResourceRepository = identityResourceRepository; + GuidGenerator = guidGenerator; + ClaimTypeRepository = claimTypeRepository; + } - public virtual async Task CreateStandardResourcesAsync() + public virtual async Task CreateStandardResourcesAsync() + { + var resources = new[] { - var resources = new[] - { new IdentityServer4.Models.IdentityResources.OpenId(), new IdentityServer4.Models.IdentityResources.Profile(), new IdentityServer4.Models.IdentityResources.Email(), @@ -33,46 +33,45 @@ namespace Volo.Abp.IdentityServer.IdentityResources new IdentityServer4.Models.IdentityResource("role", "Roles of the user", new[] {"role"}) }; - foreach (var resource in resources) - { - foreach (var claimType in resource.UserClaims) - { - await AddClaimTypeIfNotExistsAsync(claimType); - } - - await AddIdentityResourceIfNotExistsAsync(resource); - } - } - - protected virtual async Task AddIdentityResourceIfNotExistsAsync(IdentityServer4.Models.IdentityResource resource) + foreach (var resource in resources) { - if (await IdentityResourceRepository.CheckNameExistAsync(resource.Name)) + foreach (var claimType in resource.UserClaims) { - return; + await AddClaimTypeIfNotExistsAsync(claimType); } - await IdentityResourceRepository.InsertAsync( - new IdentityResource( - GuidGenerator.Create(), - resource - ) - ); + await AddIdentityResourceIfNotExistsAsync(resource); } + } - protected virtual async Task AddClaimTypeIfNotExistsAsync(string claimType) + protected virtual async Task AddIdentityResourceIfNotExistsAsync(IdentityServer4.Models.IdentityResource resource) + { + if (await IdentityResourceRepository.CheckNameExistAsync(resource.Name)) { - if (await ClaimTypeRepository.AnyAsync(claimType)) - { - return; - } + return; + } - await ClaimTypeRepository.InsertAsync( - new IdentityClaimType( - GuidGenerator.Create(), - claimType, - isStatic: true - ) - ); + await IdentityResourceRepository.InsertAsync( + new IdentityResource( + GuidGenerator.Create(), + resource + ) + ); + } + + protected virtual async Task AddClaimTypeIfNotExistsAsync(string claimType) + { + if (await ClaimTypeRepository.AnyAsync(claimType)) + { + return; } + + await ClaimTypeRepository.InsertAsync( + new IdentityClaimType( + GuidGenerator.Create(), + claimType, + isStatic: true + ) + ); } } 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 index 4480fdab5a..40e08354f1 100644 --- 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 @@ -2,38 +2,37 @@ using System.Diagnostics.CodeAnalysis; using Volo.Abp.Domain.Entities; -namespace Volo.Abp.IdentityServer.IdentityResources +namespace Volo.Abp.IdentityServer.IdentityResources; + +public class IdentityResourceProperty : Entity { - public class IdentityResourceProperty : Entity - { - public virtual Guid IdentityResourceId { get; set; } + public virtual Guid IdentityResourceId { get; set; } - public virtual string Key { get; set; } + public virtual string Key { get; set; } - public virtual string Value { get; set; } + public virtual string Value { get; set; } - protected IdentityResourceProperty() - { + protected IdentityResourceProperty() + { - } + } - public virtual bool Equals(Guid identityResourceId, [NotNull] string key, string value) - { - return IdentityResourceId == identityResourceId && Key == key && Value == value; - } + public virtual bool Equals(Guid identityResourceId, [NotNull] string key, string value) + { + return IdentityResourceId == identityResourceId && Key == key && Value == value; + } - protected internal IdentityResourceProperty(Guid identityResourceId, [NotNull] string key, [NotNull] string value) - { - Check.NotNull(key, nameof(key)); + protected internal IdentityResourceProperty(Guid identityResourceId, [NotNull] string key, [NotNull] string value) + { + Check.NotNull(key, nameof(key)); - IdentityResourceId = identityResourceId; - Key = key; - Value = value; - } + IdentityResourceId = identityResourceId; + Key = key; + Value = value; + } - public override object[] GetKeys() - { - return new object[] { IdentityResourceId, Key }; - } + 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 697050e292..3e63b4d7ab 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 @@ -8,148 +8,147 @@ using Volo.Abp.IdentityServer.Devices; using Volo.Abp.IdentityServer.Grants; using Volo.Abp.IdentityServer.IdentityResources; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class IdentityServerAutoMapperProfile : Profile { - public class IdentityServerAutoMapperProfile : Profile + /// + /// TODO: Reverse maps will not used probably. Remove those will not used + /// + public IdentityServerAutoMapperProfile() + { + CreateMap() + .ConstructUsing(src => src.Type) + .ReverseMap() + .ForMember(dest => dest.Type, opt => opt.MapFrom(src => src)); + + CreateClientMap(); + CreateApiResourceMap(); + CreateApiScopeMap(); + CreateIdentityResourceMap(); + CreatePersistedGrantMap(); + CreateDeviceFlowCodesMap(); + } + + private void CreateClientMap() + { + CreateMap() + .ConstructUsing(src => src.Origin) + .ReverseMap() + .ForMember(dest => dest.Origin, opt => opt.MapFrom(src => src)); + + CreateMap>() + .ReverseMap(); + + CreateMap() + .ForMember(dest => dest.ProtocolType, opt => opt.Condition(srs => srs != null)) + .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) + .ReverseMap() + .ForMember(dest => dest.Origin, opt => opt.MapFrom(src => src)); + + CreateMap() + .ConstructUsing(src => src.Provider) + .ReverseMap() + .ForMember(dest => dest.Provider, opt => opt.MapFrom(src => src)); + + CreateMap(MemberList.None) + .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() + .ForMember(dest => dest.Scope, opt => opt.MapFrom(src => src)); + + CreateMap() + .ConstructUsing(src => src.PostLogoutRedirectUri) + .ReverseMap() + .ForMember(dest => dest.PostLogoutRedirectUri, opt => opt.MapFrom(src => src)); + + CreateMap() + .ConstructUsing(src => src.RedirectUri) + .ReverseMap() + .ForMember(dest => dest.RedirectUri, opt => opt.MapFrom(src => src)); + + CreateMap() + .ConstructUsing(src => src.GrantType) + .ReverseMap() + .ForMember(dest => dest.GrantType, opt => opt.MapFrom(src => src)); + + CreateMap(MemberList.Destination) + .ForMember(dest => dest.Type, opt => opt.Condition(srs => srs != null)) + .ReverseMap(); + + CreateMap(); + } + + private void CreateApiResourceMap() + { + CreateMap() + .ForMember(dest => dest.ApiSecrets, opt => opt.MapFrom(src => src.Secrets)); + + CreateMap(); + + CreateMap() + .ConstructUsing(x => x.Scope) + .ReverseMap() + .ForMember(dest => dest.Scope, opt => opt.MapFrom(src => src)); + + CreateMap>() + .ReverseMap(); + + CreateMap(); + } + + private void CreateApiScopeMap() + { + 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(); + } + + private void CreateIdentityResourceMap() + { + 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(); + } + + private void CreatePersistedGrantMap() + { + //TODO: Why PersistedGrant mapping is in this profile? + CreateMap().ReverseMap(); + CreateMap(); + } + + private void CreateDeviceFlowCodesMap() { - /// - /// TODO: Reverse maps will not used probably. Remove those will not used - /// - public IdentityServerAutoMapperProfile() - { - CreateMap() - .ConstructUsing(src => src.Type) - .ReverseMap() - .ForMember(dest => dest.Type, opt => opt.MapFrom(src => src)); - - CreateClientMap(); - CreateApiResourceMap(); - CreateApiScopeMap(); - CreateIdentityResourceMap(); - CreatePersistedGrantMap(); - CreateDeviceFlowCodesMap(); - } - - private void CreateClientMap() - { - CreateMap() - .ConstructUsing(src => src.Origin) - .ReverseMap() - .ForMember(dest => dest.Origin, opt => opt.MapFrom(src => src)); - - CreateMap>() - .ReverseMap(); - - CreateMap() - .ForMember(dest => dest.ProtocolType, opt => opt.Condition(srs => srs != null)) - .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) - .ReverseMap() - .ForMember(dest => dest.Origin, opt => opt.MapFrom(src => src)); - - CreateMap() - .ConstructUsing(src => src.Provider) - .ReverseMap() - .ForMember(dest => dest.Provider, opt => opt.MapFrom(src => src)); - - CreateMap(MemberList.None) - .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() - .ForMember(dest => dest.Scope, opt => opt.MapFrom(src => src)); - - CreateMap() - .ConstructUsing(src => src.PostLogoutRedirectUri) - .ReverseMap() - .ForMember(dest => dest.PostLogoutRedirectUri, opt => opt.MapFrom(src => src)); - - CreateMap() - .ConstructUsing(src => src.RedirectUri) - .ReverseMap() - .ForMember(dest => dest.RedirectUri, opt => opt.MapFrom(src => src)); - - CreateMap() - .ConstructUsing(src => src.GrantType) - .ReverseMap() - .ForMember(dest => dest.GrantType, opt => opt.MapFrom(src => src)); - - CreateMap(MemberList.Destination) - .ForMember(dest => dest.Type, opt => opt.Condition(srs => srs != null)) - .ReverseMap(); - - CreateMap(); - } - - private void CreateApiResourceMap() - { - CreateMap() - .ForMember(dest => dest.ApiSecrets, opt => opt.MapFrom(src => src.Secrets)); - - CreateMap(); - - CreateMap() - .ConstructUsing(x => x.Scope) - .ReverseMap() - .ForMember(dest => dest.Scope, opt => opt.MapFrom(src => src)); - - CreateMap>() - .ReverseMap(); - - CreateMap(); - } - - private void CreateApiScopeMap() - { - 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(); - } - - private void CreateIdentityResourceMap() - { - 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(); - } - - private void CreatePersistedGrantMap() - { - //TODO: Why PersistedGrant mapping is in this profile? - CreateMap().ReverseMap(); - CreateMap(); - } - - private void CreateDeviceFlowCodesMap() - { - CreateMap(); - } + CreateMap(); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityServerBuilderExtensions.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityServerBuilderExtensions.cs index 516d400db6..d228d0a08b 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityServerBuilderExtensions.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityServerBuilderExtensions.cs @@ -4,19 +4,18 @@ using Volo.Abp.IdentityServer.Clients; using Volo.Abp.IdentityServer.Devices; using Volo.Abp.IdentityServer.Grants; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public static class IdentityServerBuilderExtensions { - public static class IdentityServerBuilderExtensions + public static IIdentityServerBuilder AddAbpStores(this IIdentityServerBuilder builder) { - public static IIdentityServerBuilder AddAbpStores(this IIdentityServerBuilder builder) - { - builder.Services.AddTransient(); - builder.Services.AddTransient(); + builder.Services.AddTransient(); + builder.Services.AddTransient(); - return builder - .AddClientStore() - .AddResourceStore() - .AddCorsPolicyService(); - } + return builder + .AddClientStore() + .AddResourceStore() + .AddCorsPolicyService(); } -} \ No newline at end of file +} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityServerCacheItemInvalidator.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityServerCacheItemInvalidator.cs index 48b2e0e730..cabd731c01 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityServerCacheItemInvalidator.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityServerCacheItemInvalidator.cs @@ -11,64 +11,63 @@ using Volo.Abp.IdentityServer.ApiResources; using Volo.Abp.IdentityServer.ApiScopes; using Volo.Abp.IdentityServer.IdentityResources; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class IdentityServerCacheItemInvalidator : + ILocalEventHandler>, + ILocalEventHandler>, + ILocalEventHandler>, + ILocalEventHandler>, + ILocalEventHandler>, + ITransientDependency { - public class IdentityServerCacheItemInvalidator : - ILocalEventHandler>, - ILocalEventHandler>, - ILocalEventHandler>, - ILocalEventHandler>, - ILocalEventHandler>, - ITransientDependency - { - protected IServiceProvider ServiceProvider { get; } + protected IServiceProvider ServiceProvider { get; } - public IdentityServerCacheItemInvalidator(IServiceProvider serviceProvider) - { - ServiceProvider = serviceProvider; - } + public IdentityServerCacheItemInvalidator(IServiceProvider serviceProvider) + { + ServiceProvider = serviceProvider; + } - public virtual async Task HandleEventAsync(EntityChangedEventData eventData) - { - var clientCache = ServiceProvider.GetRequiredService>(); - await clientCache.RemoveAsync(eventData.Entity.ClientId, considerUow: true); + public virtual async Task HandleEventAsync(EntityChangedEventData eventData) + { + var clientCache = ServiceProvider.GetRequiredService>(); + await clientCache.RemoveAsync(eventData.Entity.ClientId, considerUow: true); - var corsCache = ServiceProvider.GetRequiredService>(); - await corsCache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins); - } + var corsCache = ServiceProvider.GetRequiredService>(); + await corsCache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins); + } - public async Task HandleEventAsync(EntityChangedEventData eventData) - { - var corsCache = ServiceProvider.GetRequiredService>(); - await corsCache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins); - } + public async Task HandleEventAsync(EntityChangedEventData eventData) + { + var corsCache = ServiceProvider.GetRequiredService>(); + await corsCache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins); + } - public virtual async Task HandleEventAsync(EntityChangedEventData eventData) - { - var cache = ServiceProvider.GetRequiredService>(); - await cache.RemoveAsync(eventData.Entity.Name); + public virtual async Task HandleEventAsync(EntityChangedEventData eventData) + { + var cache = ServiceProvider.GetRequiredService>(); + await cache.RemoveAsync(eventData.Entity.Name); - var resourcesCache = ServiceProvider.GetRequiredService>(); - await resourcesCache.RemoveAsync(ResourceStore.AllResourcesKey); - } + var resourcesCache = ServiceProvider.GetRequiredService>(); + await resourcesCache.RemoveAsync(ResourceStore.AllResourcesKey); + } - public virtual async Task HandleEventAsync(EntityChangedEventData eventData) - { - var cache = ServiceProvider.GetRequiredService>(); - await cache.RemoveAsync(ResourceStore.ApiResourceNameCacheKeyPrefix + eventData.Entity.Name); - await cache.RemoveManyAsync(eventData.Entity.Scopes.Select(x => ResourceStore.ApiResourceScopeNameCacheKeyPrefix + x.Scope)); + public virtual async Task HandleEventAsync(EntityChangedEventData eventData) + { + var cache = ServiceProvider.GetRequiredService>(); + await cache.RemoveAsync(ResourceStore.ApiResourceNameCacheKeyPrefix + eventData.Entity.Name); + await cache.RemoveManyAsync(eventData.Entity.Scopes.Select(x => ResourceStore.ApiResourceScopeNameCacheKeyPrefix + x.Scope)); - var resourcesCache = ServiceProvider.GetRequiredService>(); - await resourcesCache.RemoveAsync(ResourceStore.AllResourcesKey); - } + var resourcesCache = ServiceProvider.GetRequiredService>(); + await resourcesCache.RemoveAsync(ResourceStore.AllResourcesKey); + } - public virtual async Task HandleEventAsync(EntityChangedEventData eventData) - { - var cache = ServiceProvider.GetRequiredService>(); - await cache.RemoveAsync(eventData.Entity.Name); + public virtual async Task HandleEventAsync(EntityChangedEventData eventData) + { + var cache = ServiceProvider.GetRequiredService>(); + await cache.RemoveAsync(eventData.Entity.Name); - var resourcesCache = ServiceProvider.GetRequiredService>(); - await resourcesCache.RemoveAsync(ResourceStore.AllResourcesKey); - } + var resourcesCache = ServiceProvider.GetRequiredService>(); + await resourcesCache.RemoveAsync(ResourceStore.AllResourcesKey); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Jwt/JwtTokenMiddleware.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Jwt/JwtTokenMiddleware.cs index 57ca9cc4c2..cbf6c8cb0d 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Jwt/JwtTokenMiddleware.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Jwt/JwtTokenMiddleware.cs @@ -1,27 +1,26 @@ using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Builder; -namespace Volo.Abp.IdentityServer.Jwt -{ - //TODO: Should we move this to another package..? +namespace Volo.Abp.IdentityServer.Jwt; + +//TODO: Should we move this to another package..? - public static class JwtTokenMiddleware +public static class JwtTokenMiddleware +{ + public static IApplicationBuilder UseJwtTokenMiddleware(this IApplicationBuilder app, string schema) { - public static IApplicationBuilder UseJwtTokenMiddleware(this IApplicationBuilder app, string schema) + return app.Use(async (ctx, next) => { - return app.Use(async (ctx, next) => + if (ctx.User.Identity?.IsAuthenticated != true) { - if (ctx.User.Identity?.IsAuthenticated != true) + var result = await ctx.AuthenticateAsync(schema); + if (result.Succeeded && result.Principal != null) { - var result = await ctx.AuthenticateAsync(schema); - if (result.Succeeded && result.Principal != null) - { - ctx.User = result.Principal; - } + ctx.User = result.Principal; } + } - await next(); - }); - } + await next(); + }); } -} \ No newline at end of file +} 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 a8683dddd9..d24d7e31c9 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 @@ -16,175 +16,174 @@ using ApiResource = Volo.Abp.IdentityServer.ApiResources.ApiResource; using ApiScope = Volo.Abp.IdentityServer.ApiScopes.ApiScope; using IdentityResource = Volo.Abp.IdentityServer.IdentityResources.IdentityResource; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class ResourceStore : IResourceStore { - public class ResourceStore : IResourceStore + public const string AllResourcesKey = "AllResources"; + public const string ApiResourceNameCacheKeyPrefix = "ApiResourceName_"; + public const string ApiResourceScopeNameCacheKeyPrefix = "ApiResourceScopeName_"; + + protected IIdentityResourceRepository IdentityResourceRepository { get; } + protected IApiResourceRepository ApiResourceRepository { get; } + protected IApiScopeRepository ApiScopeRepository { get; } + protected IObjectMapper ObjectMapper { get; } + protected IDistributedCache IdentityResourceCache { get; } + protected IDistributedCache ApiScopeCache { get; } + protected IDistributedCache ApiResourceCache { get; } + protected IDistributedCache ResourcesCache { get; } + protected IdentityServerOptions Options { get; } + + public ResourceStore( + IIdentityResourceRepository identityResourceRepository, + IObjectMapper objectMapper, + IApiResourceRepository apiResourceRepository, + IApiScopeRepository apiScopeRepository, + IDistributedCache identityResourceCache, + IDistributedCache apiScopeCache, + IDistributedCache apiResourceCache, + IDistributedCache resourcesCache, + IOptions options) { - public const string AllResourcesKey = "AllResources"; - public const string ApiResourceNameCacheKeyPrefix = "ApiResourceName_"; - public const string ApiResourceScopeNameCacheKeyPrefix = "ApiResourceScopeName_"; - - protected IIdentityResourceRepository IdentityResourceRepository { get; } - protected IApiResourceRepository ApiResourceRepository { get; } - protected IApiScopeRepository ApiScopeRepository { get; } - protected IObjectMapper ObjectMapper { get; } - protected IDistributedCache IdentityResourceCache { get; } - protected IDistributedCache ApiScopeCache { get; } - protected IDistributedCache ApiResourceCache { get; } - protected IDistributedCache ResourcesCache { get; } - protected IdentityServerOptions Options { get; } - - public ResourceStore( - IIdentityResourceRepository identityResourceRepository, - IObjectMapper objectMapper, - IApiResourceRepository apiResourceRepository, - IApiScopeRepository apiScopeRepository, - IDistributedCache identityResourceCache, - IDistributedCache apiScopeCache, - IDistributedCache apiResourceCache, - IDistributedCache resourcesCache, - IOptions options) - { - IdentityResourceRepository = identityResourceRepository; - ObjectMapper = objectMapper; - ApiResourceRepository = apiResourceRepository; - ApiScopeRepository = apiScopeRepository; - IdentityResourceCache = identityResourceCache; - ApiScopeCache = apiScopeCache; - ApiResourceCache = apiResourceCache; - ResourcesCache = resourcesCache; - Options = options.Value; - } + IdentityResourceRepository = identityResourceRepository; + ObjectMapper = objectMapper; + ApiResourceRepository = apiResourceRepository; + ApiScopeRepository = apiScopeRepository; + IdentityResourceCache = identityResourceCache; + ApiScopeCache = apiScopeCache; + ApiResourceCache = apiResourceCache; + ResourcesCache = resourcesCache; + Options = options.Value; + } - /// - /// Gets identity resources by scope name. - /// - public virtual async Task> FindIdentityResourcesByScopeNameAsync(IEnumerable scopeNames) - { - return await GetCacheItemsAsync( - IdentityResourceCache, - scopeNames, - async keys => await IdentityResourceRepository.GetListByScopeNameAsync(keys, includeDetails: true), - (models, cacheKeyPrefix)=> new List>> - { + /// + /// Gets identity resources by scope name. + /// + public virtual async Task> FindIdentityResourcesByScopeNameAsync(IEnumerable scopeNames) + { + return await GetCacheItemsAsync( + IdentityResourceCache, + scopeNames, + async keys => await IdentityResourceRepository.GetListByScopeNameAsync(keys, includeDetails: true), + (models, cacheKeyPrefix) => new List>> + { models.Select(x => new KeyValuePair(AddCachePrefix(x.Name, cacheKeyPrefix), x)) - }); - } + }); + } - /// - /// Gets API scopes by scope name. - /// - public virtual async Task> FindApiScopesByNameAsync(IEnumerable scopeNames) - { - return await GetCacheItemsAsync( - ApiScopeCache, - scopeNames, - async keys => await ApiScopeRepository.GetListByNameAsync(keys, includeDetails: true), - (models, cacheKeyPrefix) => new List>> - { + /// + /// Gets API scopes by scope name. + /// + public virtual async Task> FindApiScopesByNameAsync(IEnumerable scopeNames) + { + return await GetCacheItemsAsync( + ApiScopeCache, + scopeNames, + async keys => await ApiScopeRepository.GetListByNameAsync(keys, includeDetails: true), + (models, cacheKeyPrefix) => new List>> + { models.Select(x => new KeyValuePair(AddCachePrefix(x.Name, cacheKeyPrefix), x)) - }); - } + }); + } - /// - /// Gets API resources by scope name. - /// - public virtual async Task> FindApiResourcesByScopeNameAsync(IEnumerable scopeNames) + /// + /// Gets API resources by scope name. + /// + public virtual async Task> FindApiResourcesByScopeNameAsync(IEnumerable scopeNames) + { + return await GetCacheItemsAsync( + ApiResourceCache, + scopeNames, + async keys => await ApiResourceRepository.GetListByScopesAsync(keys, includeDetails: true), + (models, cacheKeyPrefix) => + { + return models + .Select(model => model.Scopes.Select(scope => new KeyValuePair(AddCachePrefix(scope, cacheKeyPrefix), model)).ToList()) + .Where(scopes => scopes.Any()).Cast>>().ToList(); + }, ApiResourceScopeNameCacheKeyPrefix); + } + + /// + /// Gets API resources by API resource name. + /// + public virtual async Task> FindApiResourcesByNameAsync(IEnumerable apiResourceNames) + { + return await GetCacheItemsAsync( + ApiResourceCache, + apiResourceNames, + async keys => await ApiResourceRepository.FindByNameAsync(keys, includeDetails: true), + (models, cacheKeyPrefix) => new List>> + { + models.Select(x => new KeyValuePair(AddCachePrefix(x.Name, cacheKeyPrefix), x)) + }, ApiResourceNameCacheKeyPrefix); + } + + /// + /// Gets all resources. + /// + public virtual async Task GetAllResourcesAsync() + { + return await ResourcesCache.GetOrAddAsync(AllResourcesKey, async () => { - return await GetCacheItemsAsync( - ApiResourceCache, - scopeNames, - async keys => await ApiResourceRepository.GetListByScopesAsync(keys, includeDetails: true), - (models, cacheKeyPrefix) => - { - return models - .Select(model => model.Scopes.Select(scope => new KeyValuePair(AddCachePrefix(scope, cacheKeyPrefix), model)).ToList()) - .Where(scopes => scopes.Any()).Cast>>().ToList(); - }, ApiResourceScopeNameCacheKeyPrefix); - } + var identityResources = await IdentityResourceRepository.GetListAsync(includeDetails: true); + var apiResources = await ApiResourceRepository.GetListAsync(includeDetails: true); + var apiScopes = await ApiScopeRepository.GetListAsync(includeDetails: true); + + return new Resources( + ObjectMapper.Map, List>(identityResources), + ObjectMapper.Map, List>(apiResources), + ObjectMapper.Map, List>(apiScopes)); + }, () => new DistributedCacheEntryOptions + { + AbsoluteExpirationRelativeToNow = Options.Caching.ClientStoreExpiration + }); + } - /// - /// Gets API resources by API resource name. - /// - public virtual async Task> FindApiResourcesByNameAsync(IEnumerable apiResourceNames) + protected virtual async Task> GetCacheItemsAsync( + IDistributedCache cache, + IEnumerable keys, + Func>> entityFactory, + Func, string, List>>> cacheItemsFactory, + string cacheKeyPrefix = null) + where TModel : class + { + var cacheItems = await cache.GetManyAsync(AddCachePrefix(keys, cacheKeyPrefix)); + if (cacheItems.All(x => x.Value != null)) { - return await GetCacheItemsAsync( - ApiResourceCache, - apiResourceNames, - async keys => await ApiResourceRepository.FindByNameAsync(keys, includeDetails: true), - (models, cacheKeyPrefix) => new List>> - { - models.Select(x => new KeyValuePair(AddCachePrefix(x.Name, cacheKeyPrefix), x)) - }, ApiResourceNameCacheKeyPrefix); + return cacheItems.Select(x => x.Value); } - /// - /// Gets all resources. - /// - public virtual async Task GetAllResourcesAsync() + var otherKeys = RemoveCachePrefix(cacheItems.Where(x => x.Value == null).Select(x => x.Key), cacheKeyPrefix).ToArray(); + var otherModels = ObjectMapper.Map, List>(await entityFactory(otherKeys)); + var otherCacheItems = cacheItemsFactory(otherModels, cacheKeyPrefix).ToList(); + foreach (var item in otherCacheItems) { - return await ResourcesCache.GetOrAddAsync(AllResourcesKey, async () => - { - var identityResources = await IdentityResourceRepository.GetListAsync(includeDetails: true); - var apiResources = await ApiResourceRepository.GetListAsync(includeDetails: true); - var apiScopes = await ApiScopeRepository.GetListAsync(includeDetails: true); - - return new Resources( - ObjectMapper.Map, List>(identityResources), - ObjectMapper.Map, List>(apiResources), - ObjectMapper.Map, List>(apiScopes)); - }, () => new DistributedCacheEntryOptions + await cache.SetManyAsync(item, new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = Options.Caching.ClientStoreExpiration }); } - protected virtual async Task> GetCacheItemsAsync( - IDistributedCache cache, - IEnumerable keys, - Func>> entityFactory, - Func, string, List>>> cacheItemsFactory, - string cacheKeyPrefix = null) - where TModel : class - { - var cacheItems = await cache.GetManyAsync(AddCachePrefix(keys, cacheKeyPrefix)); - if (cacheItems.All(x => x.Value != null)) - { - return cacheItems.Select(x => x.Value); - } - - var otherKeys = RemoveCachePrefix(cacheItems.Where(x => x.Value == null).Select(x => x.Key), cacheKeyPrefix).ToArray(); - var otherModels = ObjectMapper.Map, List>(await entityFactory(otherKeys)); - var otherCacheItems = cacheItemsFactory(otherModels, cacheKeyPrefix).ToList(); - foreach (var item in otherCacheItems) - { - await cache.SetManyAsync(item, new DistributedCacheEntryOptions - { - AbsoluteExpirationRelativeToNow = Options.Caching.ClientStoreExpiration - }); - } - - return cacheItems.Where(x => x.Value != null).Select(x => x.Value).Concat(otherModels); - } + return cacheItems.Where(x => x.Value != null).Select(x => x.Value).Concat(otherModels); + } - protected virtual IEnumerable AddCachePrefix(IEnumerable keys, string prefix) - { - return prefix == null ? keys : keys.Select(x => AddCachePrefix(x, prefix)); - } + protected virtual IEnumerable AddCachePrefix(IEnumerable keys, string prefix) + { + return prefix == null ? keys : keys.Select(x => AddCachePrefix(x, prefix)); + } - protected virtual string AddCachePrefix(string key, string prefix) - { - return prefix == null ? key : prefix + key; - } + protected virtual string AddCachePrefix(string key, string prefix) + { + return prefix == null ? key : prefix + key; + } - protected virtual IEnumerable RemoveCachePrefix(IEnumerable keys, string prefix) - { - return prefix == null ? keys : keys.Select(x => RemoveCachePrefix(x, prefix)); - } + protected virtual IEnumerable RemoveCachePrefix(IEnumerable keys, string prefix) + { + return prefix == null ? keys : keys.Select(x => RemoveCachePrefix(x, prefix)); + } - protected virtual string RemoveCachePrefix(string key, string prefix) - { - return prefix == null ? key : key.RemovePreFix(prefix); - } + protected virtual string RemoveCachePrefix(string key, string prefix) + { + return prefix == null ? key : key.RemovePreFix(prefix); } } 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 f09b4dfb49..5679275124 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 @@ -4,35 +4,34 @@ using IdentityServer4.Models; using JetBrains.Annotations; using Volo.Abp.Domain.Entities; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public abstract class Secret : Entity { - public abstract class Secret : Entity - { - public virtual string Type { get; protected set; } + public virtual string Type { get; protected set; } - public virtual string Value { get; set; } + public virtual string Value { get; set; } - public virtual string Description { get; set; } + public virtual string Description { get; set; } - public virtual DateTime? Expiration { get; set; } + public virtual DateTime? Expiration { get; set; } - protected Secret() - { + protected Secret() + { - } + } - protected Secret( - [NotNull] string value, - DateTime? expiration = null, - string type = IdentityServerConstants.SecretTypes.SharedSecret, - string description = null) - { - Check.NotNull(value, nameof(value)); + protected Secret( + [NotNull] string value, + DateTime? expiration = null, + string type = IdentityServerConstants.SecretTypes.SharedSecret, + string description = null) + { + Check.NotNull(value, nameof(value)); - Value = value; - Expiration = expiration; - Type = type; - Description = description; - } + Value = value; + Expiration = expiration; + Type = type; + Description = description; } -} \ No newline at end of file +} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Temp/IdentityServerConfig.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Temp/IdentityServerConfig.cs index 183a9b61ac..f122fb3547 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Temp/IdentityServerConfig.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Temp/IdentityServerConfig.cs @@ -1,37 +1 @@ -namespace Volo.Abp.IdentityServer.Temp -{ - //TODO: Remove! - //internal static class IdentityServerConfig - //{ - // public static IEnumerable GetApiResources() - // { - // return new List - // { - // new ApiResource("api1", "My API") - // }; - // } - - // public static IEnumerable GetClients() - // { - // return new List - // { - // new Client - // { - // ClientId = "client", - - // // no interactive user, use the clientid/secret for authentication - // AllowedGrantTypes = GrantTypes.ClientCredentials, - - // // secret for authentication - // ClientSecrets = - // { - // new IdentityServer4.Models.Secret("secret".Sha256()) - // }, - - // // scopes that client has access to - // AllowedScopes = { "api1" } - // } - // }; - // } - //} -} \ No newline at end of file +namespace Volo.Abp.IdentityServer.Temp; diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Tokens/TokenCleanupBackgroundWorker.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Tokens/TokenCleanupBackgroundWorker.cs index c424f9513c..a77cb01d8a 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Tokens/TokenCleanupBackgroundWorker.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Tokens/TokenCleanupBackgroundWorker.cs @@ -4,30 +4,29 @@ using Microsoft.Extensions.Options; using Volo.Abp.BackgroundWorkers; using Volo.Abp.Threading; -namespace Volo.Abp.IdentityServer.Tokens +namespace Volo.Abp.IdentityServer.Tokens; + +public class TokenCleanupBackgroundWorker : AsyncPeriodicBackgroundWorkerBase { - public class TokenCleanupBackgroundWorker : AsyncPeriodicBackgroundWorkerBase - { - protected TokenCleanupOptions Options { get; } + protected TokenCleanupOptions Options { get; } - public TokenCleanupBackgroundWorker( - AbpAsyncTimer timer, - IServiceScopeFactory serviceScopeFactory, - IOptions options) - : base( - timer, - serviceScopeFactory) - { - Options = options.Value; - timer.Period = Options.CleanupPeriod; - } + public TokenCleanupBackgroundWorker( + AbpAsyncTimer timer, + IServiceScopeFactory serviceScopeFactory, + IOptions options) + : base( + timer, + serviceScopeFactory) + { + Options = options.Value; + timer.Period = Options.CleanupPeriod; + } - protected async override Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext) - { - await workerContext - .ServiceProvider - .GetRequiredService() - .CleanAsync(); - } + protected async override Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext) + { + await workerContext + .ServiceProvider + .GetRequiredService() + .CleanAsync(); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Tokens/TokenCleanupOptions.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Tokens/TokenCleanupOptions.cs index 816ef6af15..6087aff1ff 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Tokens/TokenCleanupOptions.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Tokens/TokenCleanupOptions.cs @@ -1,34 +1,33 @@ using Volo.Abp.BackgroundWorkers; -namespace Volo.Abp.IdentityServer.Tokens +namespace Volo.Abp.IdentityServer.Tokens; + +public class TokenCleanupOptions { - public class TokenCleanupOptions - { - /// - /// Default: 3,600,000 ms. - /// - public int CleanupPeriod { get; set; } = 3_600_000; + /// + /// Default: 3,600,000 ms. + /// + public int CleanupPeriod { get; set; } = 3_600_000; - /// - /// Default value: 100. - /// - public int CleanupBatchSize { get; set; } = 100; + /// + /// Default value: 100. + /// + public int CleanupBatchSize { get; set; } = 100; - /// - /// The number of loop if there are - /// more than tokens in the database. - /// So, if is 10 and is 100, - /// then the cleanup worker will clean 1,000 items in one at max. - /// - /// Default value: 10. - /// - public int CleanupLoopCount { get; set; } = 10; + /// + /// The number of loop if there are + /// more than tokens in the database. + /// So, if is 10 and is 100, + /// then the cleanup worker will clean 1,000 items in one at max. + /// + /// Default value: 10. + /// + public int CleanupLoopCount { get; set; } = 10; - /// - /// Default value: true. - /// If is false, - /// this property is ignored and the cleanup worker doesn't work for this application instance. - /// - public bool IsCleanupEnabled { get; set; } = true; - } -} \ No newline at end of file + /// + /// Default value: true. + /// If is false, + /// this property is ignored and the cleanup worker doesn't work for this application instance. + /// + public bool IsCleanupEnabled { get; set; } = true; +} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Tokens/TokenCleanupService.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Tokens/TokenCleanupService.cs index dfa66b9e88..c83ed22a52 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Tokens/TokenCleanupService.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Tokens/TokenCleanupService.cs @@ -6,78 +6,77 @@ using Volo.Abp.IdentityServer.Grants; using Volo.Abp.Timing; using Volo.Abp.Uow; -namespace Volo.Abp.IdentityServer.Tokens +namespace Volo.Abp.IdentityServer.Tokens; + +public class TokenCleanupService : ITransientDependency { - public class TokenCleanupService : ITransientDependency + protected IPersistentGrantRepository PersistentGrantRepository { get; } + protected IDeviceFlowCodesRepository DeviceFlowCodesRepository { get; } + protected IClock Clock { get; } + protected TokenCleanupOptions Options { get; } + + public TokenCleanupService( + IPersistentGrantRepository persistentGrantRepository, + IDeviceFlowCodesRepository deviceFlowCodesRepository, + IClock clock, + IOptions options) { - protected IPersistentGrantRepository PersistentGrantRepository { get; } - protected IDeviceFlowCodesRepository DeviceFlowCodesRepository { get; } - protected IClock Clock { get; } - protected TokenCleanupOptions Options { get; } + PersistentGrantRepository = persistentGrantRepository; + DeviceFlowCodesRepository = deviceFlowCodesRepository; + Clock = clock; + Options = options.Value; + } - public TokenCleanupService( - IPersistentGrantRepository persistentGrantRepository, - IDeviceFlowCodesRepository deviceFlowCodesRepository, - IClock clock, - IOptions options) - { - PersistentGrantRepository = persistentGrantRepository; - DeviceFlowCodesRepository = deviceFlowCodesRepository; - Clock = clock; - Options = options.Value; - } + public virtual async Task CleanAsync() + { + await RemoveGrantsAsync() + ; - public virtual async Task CleanAsync() - { - await RemoveGrantsAsync() - ; - - await RemoveDeviceCodesAsync(); - } + await RemoveDeviceCodesAsync(); + } - [UnitOfWork] - protected virtual async Task RemoveGrantsAsync() + [UnitOfWork] + protected virtual async Task RemoveGrantsAsync() + { + for (int i = 0; i < Options.CleanupLoopCount; i++) { - for (int i = 0; i < Options.CleanupLoopCount; i++) - { - var persistentGrants = await PersistentGrantRepository - .GetListByExpirationAsync(Clock.Now, Options.CleanupBatchSize); + var persistentGrants = await PersistentGrantRepository + .GetListByExpirationAsync(Clock.Now, Options.CleanupBatchSize); - //TODO: Can be optimized if the repository implements the batch deletion - foreach (var persistentGrant in persistentGrants) - { - await PersistentGrantRepository - .DeleteAsync(persistentGrant); - } + //TODO: Can be optimized if the repository implements the batch deletion + foreach (var persistentGrant in persistentGrants) + { + await PersistentGrantRepository + .DeleteAsync(persistentGrant); + } - //No need to continue to query if it gets more than max items. - if (persistentGrants.Count < Options.CleanupBatchSize) - { - break; - } + //No need to continue to query if it gets more than max items. + if (persistentGrants.Count < Options.CleanupBatchSize) + { + break; } } + } - protected virtual async Task RemoveDeviceCodesAsync() + protected virtual async Task RemoveDeviceCodesAsync() + { + for (int i = 0; i < Options.CleanupLoopCount; i++) { - for (int i = 0; i < Options.CleanupLoopCount; i++) - { - var deviceFlowCodeses = await DeviceFlowCodesRepository - .GetListByExpirationAsync(Clock.Now, Options.CleanupBatchSize); + var deviceFlowCodeses = await DeviceFlowCodesRepository + .GetListByExpirationAsync(Clock.Now, Options.CleanupBatchSize); - //TODO: Can be optimized if the repository implements the batch deletion - foreach (var deviceFlowCodes in deviceFlowCodeses) - { - await DeviceFlowCodesRepository - .DeleteAsync(deviceFlowCodes); - } + //TODO: Can be optimized if the repository implements the batch deletion + foreach (var deviceFlowCodes in deviceFlowCodeses) + { + await DeviceFlowCodesRepository + .DeleteAsync(deviceFlowCodes); + } - //No need to continue to query if it gets more than max items. - if (deviceFlowCodeses.Count < Options.CleanupBatchSize) - { - break; - } + //No need to continue to query if it gets more than max items. + if (deviceFlowCodeses.Count < Options.CleanupBatchSize) + { + break; } } } -} \ No newline at end of file +} diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/UserClaim.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/UserClaim.cs index 7acaa695db..279f666ef9 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/UserClaim.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/UserClaim.cs @@ -1,22 +1,21 @@ using JetBrains.Annotations; using Volo.Abp.Domain.Entities; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public abstract class UserClaim : Entity { - public abstract class UserClaim : Entity - { - public virtual string Type { get; protected set; } + public virtual string Type { get; protected set; } - protected UserClaim() - { + protected UserClaim() + { - } + } - protected UserClaim([NotNull] string type) - { - Check.NotNull(type, nameof(type)); + protected UserClaim([NotNull] string type) + { + Check.NotNull(type, nameof(type)); - Type = type; - } + Type = type; } -} \ No newline at end of file +} 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 58cb6cc7ac..3b887a9c22 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 @@ -5,66 +5,65 @@ using Volo.Abp.IdentityServer.ApiScopes; using Volo.Abp.IdentityServer.Clients; using Volo.Abp.IdentityServer.IdentityResources; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public static class AbpIdentityServerEfCoreQueryableExtensions { - public static class AbpIdentityServerEfCoreQueryableExtensions + public static IQueryable IncludeDetails(this IQueryable queryable, bool include = true) { - public static IQueryable IncludeDetails(this IQueryable queryable, bool include = true) + if (!include) { - if (!include) - { - return queryable; - } - - return queryable - .Include(x => x.Secrets) - .Include(x => x.UserClaims) - .Include(x => x.Scopes) - .Include(x => x.Properties); + return queryable; } - public static IQueryable IncludeDetails(this IQueryable queryable, bool include = true) - { - if (!include) - { - return queryable; - } + return queryable + .Include(x => x.Secrets) + .Include(x => x.UserClaims) + .Include(x => x.Scopes) + .Include(x => x.Properties); + } - return queryable - .Include(x => x.UserClaims) - .Include(x => x.Properties); + public static IQueryable IncludeDetails(this IQueryable queryable, bool include = true) + { + if (!include) + { + return queryable; } + return queryable + .Include(x => x.UserClaims) + .Include(x => x.Properties); + } - public static IQueryable IncludeDetails(this IQueryable queryable, bool include = true) - { - if (!include) - { - return queryable; - } - return queryable - .Include(x => x.UserClaims) - .Include(x => x.Properties); + public static IQueryable IncludeDetails(this IQueryable queryable, bool include = true) + { + if (!include) + { + return queryable; } - public static IQueryable IncludeDetails(this IQueryable queryable, bool include = true) - { - if (!include) - { - return queryable; - } + return queryable + .Include(x => x.UserClaims) + .Include(x => x.Properties); + } - return queryable - .Include(x => x.AllowedGrantTypes) - .Include(x => x.RedirectUris) - .Include(x => x.PostLogoutRedirectUris) - .Include(x => x.AllowedScopes) - .Include(x => x.ClientSecrets) - .Include(x => x.Claims) - .Include(x => x.IdentityProviderRestrictions) - .Include(x => x.AllowedCorsOrigins) - .Include(x => x.Properties); + public static IQueryable IncludeDetails(this IQueryable queryable, bool include = true) + { + if (!include) + { + return queryable; } + + return queryable + .Include(x => x.AllowedGrantTypes) + .Include(x => x.RedirectUris) + .Include(x => x.PostLogoutRedirectUris) + .Include(x => x.AllowedScopes) + .Include(x => x.ClientSecrets) + .Include(x => x.Claims) + .Include(x => x.IdentityProviderRestrictions) + .Include(x => x.AllowedCorsOrigins) + .Include(x => x.Properties); } } 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 077f5ef25f..d754521bdc 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 @@ -9,116 +9,115 @@ using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.IdentityServer.EntityFrameworkCore; -namespace Volo.Abp.IdentityServer.ApiResources +namespace Volo.Abp.IdentityServer.ApiResources; + +public class ApiResourceRepository : EfCoreRepository, IApiResourceRepository { - public class ApiResourceRepository : EfCoreRepository, IApiResourceRepository + public ApiResourceRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) { - public ApiResourceRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) - { - } + } - public async Task FindByNameAsync(string apiResourceName, bool includeDetails = true, CancellationToken cancellationToken = default) - { - return await (await GetDbSetAsync()) - .IncludeDetails(includeDetails) - .OrderBy(apiResource => apiResource.Id) - .FirstOrDefaultAsync(apiResource => apiResource.Name == apiResourceName, GetCancellationToken(cancellationToken)); - } + public async Task FindByNameAsync(string apiResourceName, bool includeDetails = true, CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .IncludeDetails(includeDetails) + .OrderBy(apiResource => apiResource.Id) + .FirstOrDefaultAsync(apiResource => apiResource.Name == apiResourceName, GetCancellationToken(cancellationToken)); + } - public async Task> FindByNameAsync(string[] apiResourceNames, bool includeDetails = true, - CancellationToken cancellationToken = default) - { - return await (await GetDbSetAsync()) - .IncludeDetails(includeDetails) - .Where(apiResource => apiResourceNames.Contains(apiResource.Name)) - .OrderBy(apiResource => apiResource.Name) - .ToListAsync(GetCancellationToken(cancellationToken)); - } + public async Task> FindByNameAsync(string[] apiResourceNames, bool includeDetails = true, + CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .IncludeDetails(includeDetails) + .Where(apiResource => apiResourceNames.Contains(apiResource.Name)) + .OrderBy(apiResource => apiResource.Name) + .ToListAsync(GetCancellationToken(cancellationToken)); + } - public virtual async Task> GetListByScopesAsync( - string[] scopeNames, - bool includeDetails = false, - CancellationToken cancellationToken = default) - { - return await (await GetDbSetAsync()) - .IncludeDetails(includeDetails) - .Where(api => api.Scopes.Any(x => scopeNames.Contains(x.Scope))) - .ToListAsync(GetCancellationToken(cancellationToken)); - } + public virtual async Task> GetListByScopesAsync( + string[] scopeNames, + bool includeDetails = false, + CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .IncludeDetails(includeDetails) + .Where(api => api.Scopes.Any(x => scopeNames.Contains(x.Scope))) + .ToListAsync(GetCancellationToken(cancellationToken)); + } - public virtual async Task> GetListAsync( - string sorting, int skipCount, - int maxResultCount, - string filter, - bool includeDetails = false, - CancellationToken cancellationToken = default) - { - return await (await GetDbSetAsync()) - .IncludeDetails(includeDetails) - .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter) || - x.Description.Contains(filter) || - x.DisplayName.Contains(filter)) - .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(ApiResource.Name) : sorting) - .PageBy(skipCount, maxResultCount) - .ToListAsync(GetCancellationToken(cancellationToken)); - } + public virtual async Task> GetListAsync( + string sorting, int skipCount, + int maxResultCount, + string filter, + bool includeDetails = false, + CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .IncludeDetails(includeDetails) + .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter) || + x.Description.Contains(filter) || + x.DisplayName.Contains(filter)) + .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(ApiResource.Name) : sorting) + .PageBy(skipCount, maxResultCount) + .ToListAsync(GetCancellationToken(cancellationToken)); + } - public async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) - { - return await (await GetDbSetAsync()) - .WhereIf(!filter.IsNullOrWhiteSpace(), - x => x.Name.Contains(filter) || - x.Description.Contains(filter) || - x.DisplayName.Contains(filter)) - .LongCountAsync(GetCancellationToken(cancellationToken)); - } + public async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .WhereIf(!filter.IsNullOrWhiteSpace(), + x => x.Name.Contains(filter) || + x.Description.Contains(filter) || + x.DisplayName.Contains(filter)) + .LongCountAsync(GetCancellationToken(cancellationToken)); + } + + public virtual async Task CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()).AnyAsync(ar => ar.Id != expectedId && ar.Name == name, GetCancellationToken(cancellationToken)); + } - public virtual async Task CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) + public async override Task DeleteAsync(Guid id, bool autoSave = false, CancellationToken cancellationToken = default) + { + var dbContext = await GetDbContextAsync(); + + var resourceClaims = dbContext.Set().Where(sc => sc.ApiResourceId == id); + foreach (var scopeClaim in resourceClaims) { - return await (await GetDbSetAsync()).AnyAsync(ar => ar.Id != expectedId && ar.Name == name, GetCancellationToken(cancellationToken)); + dbContext.Set().Remove(scopeClaim); } - public async override Task DeleteAsync(Guid id, bool autoSave = false, CancellationToken cancellationToken = default) + var resourceScopes = dbContext.Set().Where(s => s.ApiResourceId == id); + foreach (var scope in resourceScopes) { - var dbContext = await GetDbContextAsync(); - - var resourceClaims = dbContext.Set().Where(sc => sc.ApiResourceId == id); - foreach (var scopeClaim in resourceClaims) - { - dbContext.Set().Remove(scopeClaim); - } - - var resourceScopes = dbContext.Set().Where(s => s.ApiResourceId == id); - foreach (var scope in resourceScopes) - { - dbContext.Set().Remove(scope); - } - - var resourceSecrets = dbContext.Set().Where(s => s.ApiResourceId == id); - foreach (var secret in resourceSecrets) - { - dbContext.Set().Remove(secret); - } - - var apiResourceProperties = dbContext.Set().Where(s => s.ApiResourceId == id); - foreach (var property in apiResourceProperties) - { - dbContext.Set().Remove(property); - } - - await base.DeleteAsync(id, autoSave, cancellationToken); + dbContext.Set().Remove(scope); } - [Obsolete("Use WithDetailsAsync method.")] - public override IQueryable WithDetails() + var resourceSecrets = dbContext.Set().Where(s => s.ApiResourceId == id); + foreach (var secret in resourceSecrets) { - return GetQueryable().IncludeDetails(); + dbContext.Set().Remove(secret); } - public override async Task> WithDetailsAsync() + var apiResourceProperties = dbContext.Set().Where(s => s.ApiResourceId == id); + foreach (var property in apiResourceProperties) { - return (await GetQueryableAsync()).IncludeDetails(); + dbContext.Set().Remove(property); } + + await base.DeleteAsync(id, autoSave, cancellationToken); + } + + [Obsolete("Use WithDetailsAsync method.")] + public override IQueryable WithDetails() + { + return GetQueryable().IncludeDetails(); + } + + public override async Task> WithDetailsAsync() + { + return (await GetQueryableAsync()).IncludeDetails(); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiScopes/ApiScopeRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiScopes/ApiScopeRepository.cs index ccd59fc359..dde660054d 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiScopes/ApiScopeRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiScopes/ApiScopeRepository.cs @@ -9,87 +9,86 @@ using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.IdentityServer.EntityFrameworkCore; -namespace Volo.Abp.IdentityServer.ApiScopes +namespace Volo.Abp.IdentityServer.ApiScopes; + +public class ApiScopeRepository : EfCoreRepository, IApiScopeRepository { - public class ApiScopeRepository : EfCoreRepository, IApiScopeRepository + public ApiScopeRepository(IDbContextProvider dbContextProvider) : base( + dbContextProvider) { - public ApiScopeRepository(IDbContextProvider dbContextProvider) : base( - dbContextProvider) - { - } + } - public async Task FindByNameAsync(string scopeName, bool includeDetails = true, CancellationToken cancellationToken = default) - { - return await (await GetDbSetAsync()) - .IncludeDetails(includeDetails) - .OrderBy(x=>x.Id) - .FirstOrDefaultAsync(x => x.Name == scopeName, GetCancellationToken(cancellationToken)); - } + public async Task FindByNameAsync(string scopeName, bool includeDetails = true, CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .IncludeDetails(includeDetails) + .OrderBy(x => x.Id) + .FirstOrDefaultAsync(x => x.Name == scopeName, GetCancellationToken(cancellationToken)); + } - public async Task> GetListByNameAsync(string[] scopeNames, bool includeDetails = false, - CancellationToken cancellationToken = default) - { - return await (await GetDbSetAsync()) - .IncludeDetails(includeDetails) - .Where(scope => scopeNames.Contains(scope.Name)) - .OrderBy(scope => scope.Id) - .ToListAsync(GetCancellationToken(cancellationToken)); - } + public async Task> GetListByNameAsync(string[] scopeNames, bool includeDetails = false, + CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .IncludeDetails(includeDetails) + .Where(scope => scopeNames.Contains(scope.Name)) + .OrderBy(scope => scope.Id) + .ToListAsync(GetCancellationToken(cancellationToken)); + } - public async Task> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter = null, bool includeDetails = false, CancellationToken cancellationToken = default) - { - return await (await GetDbSetAsync()) - .IncludeDetails(includeDetails) - .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter) || - x.Description.Contains(filter) || - x.DisplayName.Contains(filter)) - .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(ApiScope.Name) : sorting) - .PageBy(skipCount, maxResultCount) - .ToListAsync(GetCancellationToken(cancellationToken)); - } + public async Task> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter = null, bool includeDetails = false, CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .IncludeDetails(includeDetails) + .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter) || + x.Description.Contains(filter) || + x.DisplayName.Contains(filter)) + .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(ApiScope.Name) : sorting) + .PageBy(skipCount, maxResultCount) + .ToListAsync(GetCancellationToken(cancellationToken)); + } - public async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) - { - return await (await GetDbSetAsync()) - .WhereIf(!filter.IsNullOrWhiteSpace(), - x => x.Name.Contains(filter) || - x.Description.Contains(filter) || - x.DisplayName.Contains(filter)) - .LongCountAsync(GetCancellationToken(cancellationToken)); - } + public async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .WhereIf(!filter.IsNullOrWhiteSpace(), + x => x.Name.Contains(filter) || + x.Description.Contains(filter) || + x.DisplayName.Contains(filter)) + .LongCountAsync(GetCancellationToken(cancellationToken)); + } - public async Task CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) - { - return await (await GetDbSetAsync()).AnyAsync(x => x.Id != expectedId && x.Name == name, GetCancellationToken(cancellationToken)); - } + public async Task CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()).AnyAsync(x => x.Id != expectedId && x.Name == name, GetCancellationToken(cancellationToken)); + } - public override async Task DeleteAsync(Guid id, bool autoSave = false, CancellationToken cancellationToken = new CancellationToken()) + public override async Task DeleteAsync(Guid id, bool autoSave = false, CancellationToken cancellationToken = new CancellationToken()) + { + var dbContext = await GetDbContextAsync(); + var scopeClaims = dbContext.Set().Where(sc => sc.ApiScopeId == id); + foreach (var claim in scopeClaims) { - var dbContext = await GetDbContextAsync(); - var scopeClaims = dbContext.Set().Where(sc => sc.ApiScopeId == id); - foreach (var claim in scopeClaims) - { - dbContext.Set().Remove(claim); - } - - var scopeProperties = dbContext.Set().Where(s => s.ApiScopeId == id); - foreach (var property in scopeProperties) - { - dbContext.Set().Remove(property); - } - - await base.DeleteAsync(id, autoSave, cancellationToken); + dbContext.Set().Remove(claim); } - [Obsolete("Use WithDetailsAsync method.")] - public override IQueryable WithDetails() + var scopeProperties = dbContext.Set().Where(s => s.ApiScopeId == id); + foreach (var property in scopeProperties) { - return GetQueryable().IncludeDetails(); + dbContext.Set().Remove(property); } - public override async Task> WithDetailsAsync() - { - return (await GetQueryableAsync()).IncludeDetails(); - } + await base.DeleteAsync(id, autoSave, cancellationToken); + } + + [Obsolete("Use WithDetailsAsync method.")] + public override IQueryable WithDetails() + { + return GetQueryable().IncludeDetails(); + } + + public override async Task> WithDetailsAsync() + { + return (await GetQueryableAsync()).IncludeDetails(); } } 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 a8d9abb76f..5f0c3ba676 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 @@ -9,119 +9,118 @@ using Volo.Abp.EntityFrameworkCore; using Volo.Abp.IdentityServer.EntityFrameworkCore; using System.Linq.Dynamic.Core; -namespace Volo.Abp.IdentityServer.Clients +namespace Volo.Abp.IdentityServer.Clients; + +public class ClientRepository : EfCoreRepository, IClientRepository { - public class ClientRepository : EfCoreRepository, IClientRepository + public ClientRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) { - public ClientRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) - { + } + + public virtual async Task FindByClientIdAsync( + string clientId, + bool includeDetails = true, + CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .IncludeDetails(includeDetails) + .OrderBy(x => x.ClientId) + .FirstOrDefaultAsync(x => x.ClientId == clientId, GetCancellationToken(cancellationToken)); + } + + public virtual async Task> GetListAsync( + string sorting, int skipCount, int maxResultCount, string filter, bool includeDetails = false, + CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .IncludeDetails(includeDetails) + .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.ClientId.Contains(filter)) + .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(Client.ClientName) : sorting) + .PageBy(skipCount, maxResultCount) + .ToListAsync(GetCancellationToken(cancellationToken)); + } + + public async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.ClientId.Contains(filter)) + .LongCountAsync(GetCancellationToken(cancellationToken)); + } + + public virtual async Task> GetAllDistinctAllowedCorsOriginsAsync(CancellationToken cancellationToken = default) + { + return await (await GetDbContextAsync()).ClientCorsOrigins + .Select(x => x.Origin) + .Distinct() + .ToListAsync(GetCancellationToken(cancellationToken)); + } + + public virtual async Task CheckClientIdExistAsync(string clientId, Guid? expectedId = null, CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()).AnyAsync(c => c.Id != expectedId && c.ClientId == clientId, GetCancellationToken(cancellationToken)); + } + + public async override Task DeleteAsync(Guid id, bool autoSave = false, CancellationToken cancellationToken = default) + { + var dbContext = await GetDbContextAsync(); + + foreach (var clientGrantType in dbContext.Set().Where(x => x.ClientId == id)) + { + dbContext.Set().Remove(clientGrantType); } - public virtual async Task FindByClientIdAsync( - string clientId, - bool includeDetails = true, - CancellationToken cancellationToken = default) + foreach (var clientRedirectUri in dbContext.Set().Where(x => x.ClientId == id)) { - return await (await GetDbSetAsync()) - .IncludeDetails(includeDetails) - .OrderBy(x => x.ClientId) - .FirstOrDefaultAsync(x => x.ClientId == clientId, GetCancellationToken(cancellationToken)); + dbContext.Set().Remove(clientRedirectUri); } - public virtual async Task> GetListAsync( - string sorting, int skipCount, int maxResultCount, string filter, bool includeDetails = false, - CancellationToken cancellationToken = default) + foreach (var clientPostLogoutRedirectUri in dbContext.Set().Where(x => x.ClientId == id)) { - return await (await GetDbSetAsync()) - .IncludeDetails(includeDetails) - .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.ClientId.Contains(filter)) - .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(Client.ClientName) : sorting) - .PageBy(skipCount, maxResultCount) - .ToListAsync(GetCancellationToken(cancellationToken)); + dbContext.Set().Remove(clientPostLogoutRedirectUri); } - public async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) + foreach (var clientScope in dbContext.Set().Where(x => x.ClientId == id)) { - return await (await GetDbSetAsync()) - .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.ClientId.Contains(filter)) - .LongCountAsync(GetCancellationToken(cancellationToken)); + dbContext.Set().Remove(clientScope); } - public virtual async Task> GetAllDistinctAllowedCorsOriginsAsync(CancellationToken cancellationToken = default) + foreach (var clientSecret in dbContext.Set().Where(x => x.ClientId == id)) { - return await (await GetDbContextAsync()).ClientCorsOrigins - .Select(x => x.Origin) - .Distinct() - .ToListAsync(GetCancellationToken(cancellationToken)); + dbContext.Set().Remove(clientSecret); } - public virtual async Task CheckClientIdExistAsync(string clientId, Guid? expectedId = null, CancellationToken cancellationToken = default) + foreach (var clientClaim in dbContext.Set().Where(x => x.ClientId == id)) { - return await (await GetDbSetAsync()).AnyAsync(c => c.Id != expectedId && c.ClientId == clientId, GetCancellationToken(cancellationToken)); + dbContext.Set().Remove(clientClaim); } - public async override Task DeleteAsync(Guid id, bool autoSave = false, CancellationToken cancellationToken = default) + foreach (var clientIdPRestriction in dbContext.Set().Where(x => x.ClientId == id)) { - var dbContext = await GetDbContextAsync(); - - foreach (var clientGrantType in dbContext.Set().Where(x => x.ClientId == id)) - { - dbContext.Set().Remove(clientGrantType); - } - - foreach (var clientRedirectUri in dbContext.Set().Where(x => x.ClientId == id)) - { - dbContext.Set().Remove(clientRedirectUri); - } - - foreach (var clientPostLogoutRedirectUri in dbContext.Set().Where(x => x.ClientId == id)) - { - dbContext.Set().Remove(clientPostLogoutRedirectUri); - } - - foreach (var clientScope in dbContext.Set().Where(x => x.ClientId == id)) - { - dbContext.Set().Remove(clientScope); - } - - foreach (var clientSecret in dbContext.Set().Where(x => x.ClientId == id)) - { - dbContext.Set().Remove(clientSecret); - } - - foreach (var clientClaim in dbContext.Set().Where(x => x.ClientId == id)) - { - dbContext.Set().Remove(clientClaim); - } - - foreach (var clientIdPRestriction in dbContext.Set().Where(x => x.ClientId == id)) - { - dbContext.Set().Remove(clientIdPRestriction); - } - - foreach (var clientCorsOrigin in dbContext.Set().Where(x => x.ClientId == id)) - { - dbContext.Set().Remove(clientCorsOrigin); - } - - foreach (var clientProperty in dbContext.Set().Where(x => x.ClientId == id)) - { - dbContext.Set().Remove(clientProperty); - } - - await base.DeleteAsync(id, autoSave, cancellationToken); + dbContext.Set().Remove(clientIdPRestriction); } - [Obsolete("Use WithDetailsAsync method.")] - public override IQueryable WithDetails() + foreach (var clientCorsOrigin in dbContext.Set().Where(x => x.ClientId == id)) { - return GetQueryable().IncludeDetails(); + dbContext.Set().Remove(clientCorsOrigin); } - public override async Task> WithDetailsAsync() + foreach (var clientProperty in dbContext.Set().Where(x => x.ClientId == id)) { - return (await GetQueryableAsync()).IncludeDetails(); + dbContext.Set().Remove(clientProperty); } + + await base.DeleteAsync(id, autoSave, cancellationToken); + } + + [Obsolete("Use WithDetailsAsync method.")] + public override IQueryable WithDetails() + { + return GetQueryable().IncludeDetails(); + } + + public override async Task> WithDetailsAsync() + { + return (await GetQueryableAsync()).IncludeDetails(); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Devices/DeviceFlowCodesRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Devices/DeviceFlowCodesRepository.cs index e8c0a5e189..e9da122854 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Devices/DeviceFlowCodesRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Devices/DeviceFlowCodesRepository.cs @@ -8,43 +8,42 @@ using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.IdentityServer.EntityFrameworkCore; -namespace Volo.Abp.IdentityServer.Devices +namespace Volo.Abp.IdentityServer.Devices; + +public class DeviceFlowCodesRepository : EfCoreRepository, + IDeviceFlowCodesRepository { - public class DeviceFlowCodesRepository : EfCoreRepository, - IDeviceFlowCodesRepository + public DeviceFlowCodesRepository(IDbContextProvider dbContextProvider) + : base(dbContextProvider) { - public DeviceFlowCodesRepository(IDbContextProvider dbContextProvider) - : base(dbContextProvider) - { - } + } - public virtual async Task FindByUserCodeAsync( - string userCode, - CancellationToken cancellationToken = default) - { - return await (await GetDbSetAsync()) - .OrderBy(d => d.Id) - .FirstOrDefaultAsync(d => d.UserCode == userCode, GetCancellationToken(cancellationToken)); - } + public virtual async Task FindByUserCodeAsync( + string userCode, + CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .OrderBy(d => d.Id) + .FirstOrDefaultAsync(d => d.UserCode == userCode, GetCancellationToken(cancellationToken)); + } - public virtual async Task FindByDeviceCodeAsync( - string deviceCode, - CancellationToken cancellationToken = default) - { - return await (await GetDbSetAsync()) - .OrderBy(d => d.Id) - .FirstOrDefaultAsync(d => d.DeviceCode == deviceCode, GetCancellationToken(cancellationToken)); - } + public virtual async Task FindByDeviceCodeAsync( + string deviceCode, + CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .OrderBy(d => d.Id) + .FirstOrDefaultAsync(d => d.DeviceCode == deviceCode, GetCancellationToken(cancellationToken)); + } - public virtual async Task> GetListByExpirationAsync(DateTime maxExpirationDate, int maxResultCount, - CancellationToken cancellationToken = default) - { - return await (await GetDbSetAsync()) - .Where(x => x.Expiration != null && x.Expiration < maxExpirationDate) - .OrderBy(x => x.ClientId) - .Take(maxResultCount) - .ToListAsync(GetCancellationToken(cancellationToken)); - } + public virtual async Task> GetListByExpirationAsync(DateTime maxExpirationDate, int maxResultCount, + CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .Where(x => x.Expiration != null && x.Expiration < maxExpirationDate) + .OrderBy(x => x.ClientId) + .Take(maxResultCount) + .ToListAsync(GetCancellationToken(cancellationToken)); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/AbpIdentityServerEntityFrameworkCoreModule.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/AbpIdentityServerEntityFrameworkCoreModule.cs index adc51cd500..c7066236fa 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/AbpIdentityServerEntityFrameworkCoreModule.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/EntityFrameworkCore/AbpIdentityServerEntityFrameworkCoreModule.cs @@ -8,37 +8,36 @@ using Volo.Abp.IdentityServer.Grants; using Volo.Abp.IdentityServer.IdentityResources; using Volo.Abp.Modularity; -namespace Volo.Abp.IdentityServer.EntityFrameworkCore +namespace Volo.Abp.IdentityServer.EntityFrameworkCore; + +[DependsOn( + typeof(AbpIdentityServerDomainModule), + typeof(AbpEntityFrameworkCoreModule) + )] +public class AbpIdentityServerEntityFrameworkCoreModule : AbpModule { - [DependsOn( - typeof(AbpIdentityServerDomainModule), - typeof(AbpEntityFrameworkCoreModule) - )] - public class AbpIdentityServerEntityFrameworkCoreModule : AbpModule + public override void PreConfigureServices(ServiceConfigurationContext context) { - public override void PreConfigureServices(ServiceConfigurationContext context) - { - context.Services.PreConfigure( - builder => - { - builder.AddAbpStores(); - } - ); - } + context.Services.PreConfigure( + builder => + { + builder.AddAbpStores(); + } + ); + } - public override void ConfigureServices(ServiceConfigurationContext context) + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services.AddAbpDbContext(options => { - context.Services.AddAbpDbContext(options => - { - options.AddDefaultRepositories(); + options.AddDefaultRepositories(); - options.AddRepository(); - options.AddRepository(); - options.AddRepository(); - options.AddRepository(); - options.AddRepository(); - options.AddRepository(); - }); - } + options.AddRepository(); + options.AddRepository(); + options.AddRepository(); + options.AddRepository(); + options.AddRepository(); + options.AddRepository(); + }); } } 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 965c5da7da..422bee7242 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 @@ -9,72 +9,71 @@ using Volo.Abp.IdentityServer.Grants; using Volo.Abp.IdentityServer.IdentityResources; using Volo.Abp.MultiTenancy; -namespace Volo.Abp.IdentityServer.EntityFrameworkCore +namespace Volo.Abp.IdentityServer.EntityFrameworkCore; + +[IgnoreMultiTenancy] +[ConnectionStringName(AbpIdentityServerDbProperties.ConnectionStringName)] +public interface IIdentityServerDbContext : IEfCoreDbContext { - [IgnoreMultiTenancy] - [ConnectionStringName(AbpIdentityServerDbProperties.ConnectionStringName)] - public interface IIdentityServerDbContext : IEfCoreDbContext - { - #region ApiResource + #region ApiResource - DbSet ApiResources { get; } + DbSet ApiResources { get; } - DbSet ApiResourceSecrets { get; } + DbSet ApiResourceSecrets { get; } - DbSet ApiResourceClaims { get; } + DbSet ApiResourceClaims { get; } - DbSet ApiResourceScopes { get; } + DbSet ApiResourceScopes { get; } - DbSet ApiResourceProperties { get; } + DbSet ApiResourceProperties { get; } - #endregion + #endregion - #region ApiScope + #region ApiScope - DbSet ApiScopes { get; } + DbSet ApiScopes { get; } - DbSet ApiScopeClaims { get; } + DbSet ApiScopeClaims { get; } - DbSet ApiScopeProperties { get; } + DbSet ApiScopeProperties { get; } - #endregion + #endregion - #region IdentityResource + #region IdentityResource - DbSet IdentityResources { get; } + DbSet IdentityResources { get; } - DbSet IdentityClaims { get; } + DbSet IdentityClaims { get; } - DbSet IdentityResourceProperties { get; } + DbSet IdentityResourceProperties { get; } - #endregion + #endregion - #region Client + #region Client - DbSet Clients { get; } + DbSet Clients { get; } - DbSet ClientGrantTypes { get; } + DbSet ClientGrantTypes { get; } - DbSet ClientRedirectUris { get; } + DbSet ClientRedirectUris { get; } - DbSet ClientPostLogoutRedirectUris { get; } + DbSet ClientPostLogoutRedirectUris { get; } - DbSet ClientScopes { get; } + DbSet ClientScopes { get; } - DbSet ClientSecrets { get; } + DbSet ClientSecrets { get; } - DbSet ClientClaims { get; } + DbSet ClientClaims { get; } - DbSet ClientIdPRestrictions { get; } + DbSet ClientIdPRestrictions { get; } - DbSet ClientCorsOrigins { get; } + DbSet ClientCorsOrigins { get; } - DbSet ClientProperties { get; } + DbSet ClientProperties { get; } - #endregion + #endregion - DbSet PersistedGrants { get; } + DbSet PersistedGrants { get; } - DbSet DeviceFlowCodes { get; } - } + DbSet DeviceFlowCodes { get; } } 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 236c6f8e66..07c0030116 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 @@ -9,85 +9,84 @@ using Volo.Abp.IdentityServer.Grants; using Volo.Abp.IdentityServer.IdentityResources; using Volo.Abp.MultiTenancy; -namespace Volo.Abp.IdentityServer.EntityFrameworkCore +namespace Volo.Abp.IdentityServer.EntityFrameworkCore; + +[IgnoreMultiTenancy] +[ConnectionStringName(AbpIdentityServerDbProperties.ConnectionStringName)] +public class IdentityServerDbContext : AbpDbContext, IIdentityServerDbContext { - [IgnoreMultiTenancy] - [ConnectionStringName(AbpIdentityServerDbProperties.ConnectionStringName)] - public class IdentityServerDbContext : AbpDbContext, IIdentityServerDbContext - { - #region ApiResource + #region ApiResource - public DbSet ApiResources { get; set; } + public DbSet ApiResources { get; set; } - public DbSet ApiResourceSecrets { get; set; } + public DbSet ApiResourceSecrets { get; set; } - public DbSet ApiResourceClaims { get; set; } + public DbSet ApiResourceClaims { get; set; } - public DbSet ApiResourceScopes { get; set; } + public DbSet ApiResourceScopes { get; set; } - public DbSet ApiResourceProperties { get; set; } + public DbSet ApiResourceProperties { get; set; } - #endregion + #endregion - #region ApiScope + #region ApiScope - public DbSet ApiScopes { get; set; } + public DbSet ApiScopes { get; set; } - public DbSet ApiScopeClaims { get; set; } + public DbSet ApiScopeClaims { get; set; } - public DbSet ApiScopeProperties { get; set; } + public DbSet ApiScopeProperties { get; set; } - #endregion + #endregion - #region IdentityResource + #region IdentityResource - public DbSet IdentityResources { get; set; } + public DbSet IdentityResources { get; set; } - public DbSet IdentityClaims { get; set; } + public DbSet IdentityClaims { get; set; } - public DbSet IdentityResourceProperties { get; set; } + public DbSet IdentityResourceProperties { get; set; } - #endregion + #endregion - #region Client + #region Client - public DbSet Clients { get; set; } + public DbSet Clients { get; set; } - public DbSet ClientGrantTypes { get; set; } + public DbSet ClientGrantTypes { get; set; } - public DbSet ClientRedirectUris { get; set; } + public DbSet ClientRedirectUris { get; set; } - public DbSet ClientPostLogoutRedirectUris { get; set; } + public DbSet ClientPostLogoutRedirectUris { get; set; } - public DbSet ClientScopes { get; set; } + public DbSet ClientScopes { get; set; } - public DbSet ClientSecrets { get; set; } + public DbSet ClientSecrets { get; set; } - public DbSet ClientClaims { get; set; } + public DbSet ClientClaims { get; set; } - public DbSet ClientIdPRestrictions { get; set; } + public DbSet ClientIdPRestrictions { get; set; } - public DbSet ClientCorsOrigins { get; set; } + public DbSet ClientCorsOrigins { get; set; } - public DbSet ClientProperties { get; set; } + public DbSet ClientProperties { get; set; } - #endregion + #endregion - public DbSet PersistedGrants { get; set; } + public DbSet PersistedGrants { get; set; } - public DbSet DeviceFlowCodes { get; set; } + public DbSet DeviceFlowCodes { get; set; } - public IdentityServerDbContext(DbContextOptions options) - : base(options) - { + public IdentityServerDbContext(DbContextOptions options) + : base(options) + { - } + } - protected override void OnModelCreating(ModelBuilder builder) - { - base.OnModelCreating(builder); + protected override void OnModelCreating(ModelBuilder builder) + { + base.OnModelCreating(builder); - builder.ConfigureIdentityServer(); - } + builder.ConfigureIdentityServer(); } } 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 609ebebf2c..6454902999 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 @@ -8,471 +8,470 @@ using Volo.Abp.IdentityServer.Devices; using Volo.Abp.IdentityServer.Grants; using Volo.Abp.IdentityServer.IdentityResources; -namespace Volo.Abp.IdentityServer.EntityFrameworkCore +namespace Volo.Abp.IdentityServer.EntityFrameworkCore; + +public static class IdentityServerDbContextModelCreatingExtensions { - public static class IdentityServerDbContextModelCreatingExtensions + public static void ConfigureIdentityServer( + this ModelBuilder builder) { - public static void ConfigureIdentityServer( - this ModelBuilder builder) + Check.NotNull(builder, nameof(builder)); + + if (builder.IsTenantOnlyDatabase()) { - Check.NotNull(builder, nameof(builder)); + return; + } - if (builder.IsTenantOnlyDatabase()) - { - return; - } + #region Client - #region Client + builder.Entity(b => + { + b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "Clients", AbpIdentityServerDbProperties.DbSchema); + + b.ConfigureByConvention(); + + b.Property(x => x.ClientId).HasMaxLength(ClientConsts.ClientIdMaxLength).IsRequired(); + b.Property(x => x.ProtocolType).HasMaxLength(ClientConsts.ProtocolTypeMaxLength).IsRequired(); + b.Property(x => x.ClientName).HasMaxLength(ClientConsts.ClientNameMaxLength); + b.Property(x => x.ClientUri).HasMaxLength(ClientConsts.ClientUriMaxLength); + b.Property(x => x.LogoUri).HasMaxLength(ClientConsts.LogoUriMaxLength); + b.Property(x => x.Description).HasMaxLength(ClientConsts.DescriptionMaxLength); + b.Property(x => x.FrontChannelLogoutUri).HasMaxLength(ClientConsts.FrontChannelLogoutUriMaxLength); + b.Property(x => x.BackChannelLogoutUri).HasMaxLength(ClientConsts.BackChannelLogoutUriMaxLength); + b.Property(x => x.ClientClaimsPrefix).HasMaxLength(ClientConsts.ClientClaimsPrefixMaxLength); + b.Property(x => x.PairWiseSubjectSalt).HasMaxLength(ClientConsts.PairWiseSubjectSaltMaxLength); + b.Property(x => x.UserCodeType).HasMaxLength(ClientConsts.UserCodeTypeMaxLength); + b.Property(x => x.AllowedIdentityTokenSigningAlgorithms).HasMaxLength(ClientConsts.AllowedIdentityTokenSigningAlgorithms); + + b.HasMany(x => x.AllowedScopes).WithOne().HasForeignKey(x => x.ClientId).IsRequired(); + b.HasMany(x => x.ClientSecrets).WithOne().HasForeignKey(x => x.ClientId).IsRequired(); + b.HasMany(x => x.AllowedGrantTypes).WithOne().HasForeignKey(x => x.ClientId).IsRequired(); + b.HasMany(x => x.AllowedCorsOrigins).WithOne().HasForeignKey(x => x.ClientId).IsRequired(); + b.HasMany(x => x.RedirectUris).WithOne().HasForeignKey(x => x.ClientId).IsRequired(); + b.HasMany(x => x.PostLogoutRedirectUris).WithOne().HasForeignKey(x => x.ClientId).IsRequired(); + b.HasMany(x => x.IdentityProviderRestrictions).WithOne().HasForeignKey(x => x.ClientId).IsRequired(); + b.HasMany(x => x.Claims).WithOne().HasForeignKey(x => x.ClientId).IsRequired(); + b.HasMany(x => x.Properties).WithOne().HasForeignKey(x => x.ClientId).IsRequired(); + + b.HasIndex(x => x.ClientId); + + b.ApplyObjectExtensionMappings(); + }); + + builder.Entity(b => + { + b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ClientGrantTypes", AbpIdentityServerDbProperties.DbSchema); - builder.Entity(b => - { - b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "Clients", AbpIdentityServerDbProperties.DbSchema); - - b.ConfigureByConvention(); - - b.Property(x => x.ClientId).HasMaxLength(ClientConsts.ClientIdMaxLength).IsRequired(); - b.Property(x => x.ProtocolType).HasMaxLength(ClientConsts.ProtocolTypeMaxLength).IsRequired(); - b.Property(x => x.ClientName).HasMaxLength(ClientConsts.ClientNameMaxLength); - b.Property(x => x.ClientUri).HasMaxLength(ClientConsts.ClientUriMaxLength); - b.Property(x => x.LogoUri).HasMaxLength(ClientConsts.LogoUriMaxLength); - b.Property(x => x.Description).HasMaxLength(ClientConsts.DescriptionMaxLength); - b.Property(x => x.FrontChannelLogoutUri).HasMaxLength(ClientConsts.FrontChannelLogoutUriMaxLength); - b.Property(x => x.BackChannelLogoutUri).HasMaxLength(ClientConsts.BackChannelLogoutUriMaxLength); - b.Property(x => x.ClientClaimsPrefix).HasMaxLength(ClientConsts.ClientClaimsPrefixMaxLength); - b.Property(x => x.PairWiseSubjectSalt).HasMaxLength(ClientConsts.PairWiseSubjectSaltMaxLength); - b.Property(x => x.UserCodeType).HasMaxLength(ClientConsts.UserCodeTypeMaxLength); - b.Property(x => x.AllowedIdentityTokenSigningAlgorithms).HasMaxLength(ClientConsts.AllowedIdentityTokenSigningAlgorithms); - - b.HasMany(x => x.AllowedScopes).WithOne().HasForeignKey(x => x.ClientId).IsRequired(); - b.HasMany(x => x.ClientSecrets).WithOne().HasForeignKey(x => x.ClientId).IsRequired(); - b.HasMany(x => x.AllowedGrantTypes).WithOne().HasForeignKey(x => x.ClientId).IsRequired(); - b.HasMany(x => x.AllowedCorsOrigins).WithOne().HasForeignKey(x => x.ClientId).IsRequired(); - b.HasMany(x => x.RedirectUris).WithOne().HasForeignKey(x => x.ClientId).IsRequired(); - b.HasMany(x => x.PostLogoutRedirectUris).WithOne().HasForeignKey(x => x.ClientId).IsRequired(); - b.HasMany(x => x.IdentityProviderRestrictions).WithOne().HasForeignKey(x => x.ClientId).IsRequired(); - b.HasMany(x => x.Claims).WithOne().HasForeignKey(x => x.ClientId).IsRequired(); - b.HasMany(x => x.Properties).WithOne().HasForeignKey(x => x.ClientId).IsRequired(); - - b.HasIndex(x => x.ClientId); - - b.ApplyObjectExtensionMappings(); - }); - - builder.Entity(b => - { - b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ClientGrantTypes", AbpIdentityServerDbProperties.DbSchema); + b.ConfigureByConvention(); - b.ConfigureByConvention(); + b.HasKey(x => new { x.ClientId, x.GrantType }); - b.HasKey(x => new {x.ClientId, x.GrantType}); + b.Property(x => x.GrantType).HasMaxLength(ClientGrantTypeConsts.GrantTypeMaxLength).IsRequired(); - b.Property(x => x.GrantType).HasMaxLength(ClientGrantTypeConsts.GrantTypeMaxLength).IsRequired(); + b.ApplyObjectExtensionMappings(); + }); - b.ApplyObjectExtensionMappings(); - }); + builder.Entity(b => + { + b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ClientRedirectUris", AbpIdentityServerDbProperties.DbSchema); + + b.ConfigureByConvention(); - builder.Entity(b => + b.HasKey(x => new { x.ClientId, x.RedirectUri }); + + if (IsDatabaseProvider(builder, EfCoreDatabaseProvider.MySql)) { - b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ClientRedirectUris", AbpIdentityServerDbProperties.DbSchema); + ClientRedirectUriConsts.RedirectUriMaxLengthValue = 300; + } - b.ConfigureByConvention(); + b.Property(x => x.RedirectUri).HasMaxLength(ClientRedirectUriConsts.RedirectUriMaxLengthValue).IsRequired(); - b.HasKey(x => new {x.ClientId, x.RedirectUri}); + b.ApplyObjectExtensionMappings(); + }); - if (IsDatabaseProvider(builder, EfCoreDatabaseProvider.MySql)) - { - ClientRedirectUriConsts.RedirectUriMaxLengthValue = 300; - } + builder.Entity(b => + { + b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ClientPostLogoutRedirectUris", AbpIdentityServerDbProperties.DbSchema); - b.Property(x => x.RedirectUri).HasMaxLength(ClientRedirectUriConsts.RedirectUriMaxLengthValue).IsRequired(); + b.ConfigureByConvention(); - b.ApplyObjectExtensionMappings(); - }); + b.HasKey(x => new { x.ClientId, x.PostLogoutRedirectUri }); - builder.Entity(b => + if (IsDatabaseProvider(builder, EfCoreDatabaseProvider.MySql)) { - b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ClientPostLogoutRedirectUris", AbpIdentityServerDbProperties.DbSchema); + ClientPostLogoutRedirectUriConsts.PostLogoutRedirectUriMaxLengthValue = 300; + } - b.ConfigureByConvention(); + b.Property(x => x.PostLogoutRedirectUri) + .HasMaxLength(ClientPostLogoutRedirectUriConsts.PostLogoutRedirectUriMaxLengthValue) + .IsRequired(); - b.HasKey(x => new {x.ClientId, x.PostLogoutRedirectUri}); + b.ApplyObjectExtensionMappings(); + }); - if (IsDatabaseProvider(builder, EfCoreDatabaseProvider.MySql)) - { - ClientPostLogoutRedirectUriConsts.PostLogoutRedirectUriMaxLengthValue = 300; - } + builder.Entity(b => + { + b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ClientScopes", AbpIdentityServerDbProperties.DbSchema); - b.Property(x => x.PostLogoutRedirectUri) - .HasMaxLength(ClientPostLogoutRedirectUriConsts.PostLogoutRedirectUriMaxLengthValue) - .IsRequired(); + b.ConfigureByConvention(); - b.ApplyObjectExtensionMappings(); - }); + b.HasKey(x => new { x.ClientId, x.Scope }); - builder.Entity(b => - { - b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ClientScopes", AbpIdentityServerDbProperties.DbSchema); + b.Property(x => x.Scope).HasMaxLength(ClientScopeConsts.ScopeMaxLength).IsRequired(); - b.ConfigureByConvention(); + b.ApplyObjectExtensionMappings(); + }); - b.HasKey(x => new {x.ClientId, x.Scope}); + builder.Entity(b => + { + b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ClientSecrets", AbpIdentityServerDbProperties.DbSchema); - b.Property(x => x.Scope).HasMaxLength(ClientScopeConsts.ScopeMaxLength).IsRequired(); + b.ConfigureByConvention(); - b.ApplyObjectExtensionMappings(); - }); + b.HasKey(x => new { x.ClientId, x.Type, x.Value }); - builder.Entity(b => + b.Property(x => x.Type).HasMaxLength(ClientSecretConsts.TypeMaxLength).IsRequired(); + if (IsDatabaseProvider(builder, EfCoreDatabaseProvider.MySql, EfCoreDatabaseProvider.Oracle)) { - b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ClientSecrets", AbpIdentityServerDbProperties.DbSchema); + ClientSecretConsts.ValueMaxLength = 300; + } + b.Property(x => x.Value).HasMaxLength(ClientSecretConsts.ValueMaxLength).IsRequired(); + b.Property(x => x.Description).HasMaxLength(ClientSecretConsts.DescriptionMaxLength); - b.ConfigureByConvention(); + b.ApplyObjectExtensionMappings(); + }); - b.HasKey(x => new {x.ClientId, x.Type, x.Value}); + builder.Entity(b => + { + b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ClientClaims", AbpIdentityServerDbProperties.DbSchema); - b.Property(x => x.Type).HasMaxLength(ClientSecretConsts.TypeMaxLength).IsRequired(); - if (IsDatabaseProvider(builder, EfCoreDatabaseProvider.MySql, EfCoreDatabaseProvider.Oracle)) - { - ClientSecretConsts.ValueMaxLength = 300; - } - b.Property(x => x.Value).HasMaxLength(ClientSecretConsts.ValueMaxLength).IsRequired(); - b.Property(x => x.Description).HasMaxLength(ClientSecretConsts.DescriptionMaxLength); + b.ConfigureByConvention(); - b.ApplyObjectExtensionMappings(); - }); + b.HasKey(x => new { x.ClientId, x.Type, x.Value }); - builder.Entity(b => - { - b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ClientClaims", AbpIdentityServerDbProperties.DbSchema); + b.Property(x => x.Type).HasMaxLength(ClientClaimConsts.TypeMaxLength).IsRequired(); + b.Property(x => x.Value).HasMaxLength(ClientClaimConsts.ValueMaxLength).IsRequired(); - b.ConfigureByConvention(); + b.ApplyObjectExtensionMappings(); + }); - b.HasKey(x => new {x.ClientId, x.Type, x.Value}); + builder.Entity(b => + { + b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ClientIdPRestrictions", AbpIdentityServerDbProperties.DbSchema); - b.Property(x => x.Type).HasMaxLength(ClientClaimConsts.TypeMaxLength).IsRequired(); - b.Property(x => x.Value).HasMaxLength(ClientClaimConsts.ValueMaxLength).IsRequired(); + b.ConfigureByConvention(); - b.ApplyObjectExtensionMappings(); - }); + b.HasKey(x => new { x.ClientId, x.Provider }); - builder.Entity(b => - { - b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ClientIdPRestrictions", AbpIdentityServerDbProperties.DbSchema); + b.Property(x => x.Provider).HasMaxLength(ClientIdPRestrictionConsts.ProviderMaxLength).IsRequired(); - b.ConfigureByConvention(); + b.ApplyObjectExtensionMappings(); + }); - b.HasKey(x => new {x.ClientId, x.Provider}); + builder.Entity(b => + { + b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ClientCorsOrigins", AbpIdentityServerDbProperties.DbSchema); - b.Property(x => x.Provider).HasMaxLength(ClientIdPRestrictionConsts.ProviderMaxLength).IsRequired(); + b.ConfigureByConvention(); - b.ApplyObjectExtensionMappings(); - }); + b.HasKey(x => new { x.ClientId, x.Origin }); - builder.Entity(b => - { - b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ClientCorsOrigins", AbpIdentityServerDbProperties.DbSchema); + b.Property(x => x.Origin).HasMaxLength(ClientCorsOriginConsts.OriginMaxLength).IsRequired(); - b.ConfigureByConvention(); + b.ApplyObjectExtensionMappings(); + }); - b.HasKey(x => new {x.ClientId, x.Origin}); + builder.Entity(b => + { + b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ClientProperties", AbpIdentityServerDbProperties.DbSchema); - b.Property(x => x.Origin).HasMaxLength(ClientCorsOriginConsts.OriginMaxLength).IsRequired(); + b.ConfigureByConvention(); - b.ApplyObjectExtensionMappings(); - }); + b.HasKey(x => new { x.ClientId, x.Key, x.Value }); - builder.Entity(b => + b.Property(x => x.Key).HasMaxLength(ClientPropertyConsts.KeyMaxLength).IsRequired(); + if (IsDatabaseProvider(builder, EfCoreDatabaseProvider.MySql)) { - b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ClientProperties", AbpIdentityServerDbProperties.DbSchema); + ClientPropertyConsts.ValueMaxLength = 300; + } + b.Property(x => x.Value).HasMaxLength(ClientPropertyConsts.ValueMaxLength).IsRequired(); - b.ConfigureByConvention(); + b.ApplyObjectExtensionMappings(); + }); - b.HasKey(x => new {x.ClientId, x.Key, x.Value}); + #endregion - b.Property(x => x.Key).HasMaxLength(ClientPropertyConsts.KeyMaxLength).IsRequired(); - if (IsDatabaseProvider(builder, EfCoreDatabaseProvider.MySql)) - { - ClientPropertyConsts.ValueMaxLength = 300; - } - b.Property(x => x.Value).HasMaxLength(ClientPropertyConsts.ValueMaxLength).IsRequired(); + #region IdentityResource - b.ApplyObjectExtensionMappings(); - }); + builder.Entity(b => + { + b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "IdentityResources", AbpIdentityServerDbProperties.DbSchema); - #endregion + b.ConfigureByConvention(); - #region IdentityResource + 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); - builder.Entity(b => - { - b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "IdentityResources", AbpIdentityServerDbProperties.DbSchema); + b.HasMany(x => x.UserClaims).WithOne().HasForeignKey(x => x.IdentityResourceId).IsRequired(); + b.HasMany(x => x.Properties).WithOne().HasForeignKey(x => x.IdentityResourceId).IsRequired(); - b.ConfigureByConvention(); + b.ApplyObjectExtensionMappings(); + }); - 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); + builder.Entity(b => + { + b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "IdentityResourceClaims", AbpIdentityServerDbProperties.DbSchema); - b.HasMany(x => x.UserClaims).WithOne().HasForeignKey(x => x.IdentityResourceId).IsRequired(); - b.HasMany(x => x.Properties).WithOne().HasForeignKey(x => x.IdentityResourceId).IsRequired(); + b.ConfigureByConvention(); - b.ApplyObjectExtensionMappings(); - }); + b.HasKey(x => new { x.IdentityResourceId, x.Type }); - builder.Entity(b => - { - b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "IdentityResourceClaims", AbpIdentityServerDbProperties.DbSchema); + b.Property(x => x.Type).HasMaxLength(UserClaimConsts.TypeMaxLength).IsRequired(); - b.ConfigureByConvention(); + b.ApplyObjectExtensionMappings(); + }); - b.HasKey(x => new {x.IdentityResourceId, x.Type}); + builder.Entity(b => + { + b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "IdentityResourceProperties", AbpIdentityServerDbProperties.DbSchema); - b.Property(x => x.Type).HasMaxLength(UserClaimConsts.TypeMaxLength).IsRequired(); + b.ConfigureByConvention(); - b.ApplyObjectExtensionMappings(); - }); + b.HasKey(x => new { x.IdentityResourceId, x.Key, x.Value }); - builder.Entity(b => + b.Property(x => x.Key).HasMaxLength(IdentityResourcePropertyConsts.KeyMaxLength).IsRequired(); + if (IsDatabaseProvider(builder, EfCoreDatabaseProvider.MySql, EfCoreDatabaseProvider.Oracle)) { - b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "IdentityResourceProperties", AbpIdentityServerDbProperties.DbSchema); + IdentityResourcePropertyConsts.ValueMaxLength = 300; + } + b.Property(x => x.Value).HasMaxLength(IdentityResourcePropertyConsts.ValueMaxLength).IsRequired(); - b.ConfigureByConvention(); + b.ApplyObjectExtensionMappings(); + }); - b.HasKey(x => new {x.IdentityResourceId, x.Key, x.Value}); + #endregion - b.Property(x => x.Key).HasMaxLength(IdentityResourcePropertyConsts.KeyMaxLength).IsRequired(); - if (IsDatabaseProvider(builder, EfCoreDatabaseProvider.MySql, EfCoreDatabaseProvider.Oracle)) - { - IdentityResourcePropertyConsts.ValueMaxLength = 300; - } - b.Property(x => x.Value).HasMaxLength(IdentityResourcePropertyConsts.ValueMaxLength).IsRequired(); + #region ApiResource - b.ApplyObjectExtensionMappings(); - }); + builder.Entity(b => + { + b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ApiResources", AbpIdentityServerDbProperties.DbSchema); - #endregion + b.ConfigureByConvention(); - #region ApiResource + b.Property(x => x.Name).HasMaxLength(ApiResourceConsts.NameMaxLength).IsRequired(); + b.Property(x => x.DisplayName).HasMaxLength(ApiResourceConsts.DisplayNameMaxLength); + b.Property(x => x.Description).HasMaxLength(ApiResourceConsts.DescriptionMaxLength); + b.Property(x => x.AllowedAccessTokenSigningAlgorithms).HasMaxLength(ApiResourceConsts.AllowedAccessTokenSigningAlgorithmsMaxLength); - builder.Entity(b => - { - b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ApiResources", AbpIdentityServerDbProperties.DbSchema); + b.HasMany(x => x.Secrets).WithOne().HasForeignKey(x => x.ApiResourceId).IsRequired(); + b.HasMany(x => x.Scopes).WithOne().HasForeignKey(x => x.ApiResourceId).IsRequired(); + b.HasMany(x => x.UserClaims).WithOne().HasForeignKey(x => x.ApiResourceId).IsRequired(); + b.HasMany(x => x.Properties).WithOne().HasForeignKey(x => x.ApiResourceId).IsRequired(); - b.ConfigureByConvention(); + b.ApplyObjectExtensionMappings(); + }); - b.Property(x => x.Name).HasMaxLength(ApiResourceConsts.NameMaxLength).IsRequired(); - b.Property(x => x.DisplayName).HasMaxLength(ApiResourceConsts.DisplayNameMaxLength); - b.Property(x => x.Description).HasMaxLength(ApiResourceConsts.DescriptionMaxLength); - b.Property(x => x.AllowedAccessTokenSigningAlgorithms).HasMaxLength(ApiResourceConsts.AllowedAccessTokenSigningAlgorithmsMaxLength); + builder.Entity(b => + { + b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ApiResourceSecrets", AbpIdentityServerDbProperties.DbSchema); - b.HasMany(x => x.Secrets).WithOne().HasForeignKey(x => x.ApiResourceId).IsRequired(); - b.HasMany(x => x.Scopes).WithOne().HasForeignKey(x => x.ApiResourceId).IsRequired(); - b.HasMany(x => x.UserClaims).WithOne().HasForeignKey(x => x.ApiResourceId).IsRequired(); - b.HasMany(x => x.Properties).WithOne().HasForeignKey(x => x.ApiResourceId).IsRequired(); + b.ConfigureByConvention(); - b.ApplyObjectExtensionMappings(); - }); + b.HasKey(x => new { x.ApiResourceId, x.Type, x.Value }); - builder.Entity(b => - { - b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ApiResourceSecrets", AbpIdentityServerDbProperties.DbSchema); + b.Property(x => x.Type).HasMaxLength(ApiResourceSecretConsts.TypeMaxLength).IsRequired(); - b.ConfigureByConvention(); + if (IsDatabaseProvider(builder, EfCoreDatabaseProvider.MySql, EfCoreDatabaseProvider.Oracle)) + { + ApiResourceSecretConsts.ValueMaxLength = 300; + } + b.Property(x => x.Value).HasMaxLength(ApiResourceSecretConsts.ValueMaxLength).IsRequired(); - b.HasKey(x => new {x.ApiResourceId, x.Type, x.Value}); + b.Property(x => x.Description).HasMaxLength(ApiResourceSecretConsts.DescriptionMaxLength); - b.Property(x => x.Type).HasMaxLength(ApiResourceSecretConsts.TypeMaxLength).IsRequired(); + b.ApplyObjectExtensionMappings(); + }); - if (IsDatabaseProvider(builder, EfCoreDatabaseProvider.MySql, EfCoreDatabaseProvider.Oracle)) - { - ApiResourceSecretConsts.ValueMaxLength = 300; - } - b.Property(x => x.Value).HasMaxLength(ApiResourceSecretConsts.ValueMaxLength).IsRequired(); + builder.Entity(b => + { + b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ApiResourceClaims", AbpIdentityServerDbProperties.DbSchema); - b.Property(x => x.Description).HasMaxLength(ApiResourceSecretConsts.DescriptionMaxLength); + b.ConfigureByConvention(); - b.ApplyObjectExtensionMappings(); - }); + b.HasKey(x => new { x.ApiResourceId, x.Type }); - builder.Entity(b => - { - b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ApiResourceClaims", AbpIdentityServerDbProperties.DbSchema); + b.Property(x => x.Type).HasMaxLength(UserClaimConsts.TypeMaxLength).IsRequired(); - b.ConfigureByConvention(); + b.ApplyObjectExtensionMappings(); + }); - b.HasKey(x => new {x.ApiResourceId, x.Type}); + builder.Entity(b => + { + b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ApiResourceScopes", AbpIdentityServerDbProperties.DbSchema); - b.Property(x => x.Type).HasMaxLength(UserClaimConsts.TypeMaxLength).IsRequired(); + b.ConfigureByConvention(); - b.ApplyObjectExtensionMappings(); - }); + b.HasKey(x => new { x.ApiResourceId, x.Scope }); - builder.Entity(b => - { - b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ApiResourceScopes", AbpIdentityServerDbProperties.DbSchema); + b.Property(x => x.Scope).HasMaxLength(ApiResourceScopeConsts.ScopeMaxLength).IsRequired(); - b.ConfigureByConvention(); + b.ApplyObjectExtensionMappings(); + }); - b.HasKey(x => new {x.ApiResourceId, x.Scope}); + builder.Entity(b => + { + b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ApiResourceProperties", AbpIdentityServerDbProperties.DbSchema); - b.Property(x => x.Scope).HasMaxLength(ApiResourceScopeConsts.ScopeMaxLength).IsRequired(); + b.ConfigureByConvention(); - b.ApplyObjectExtensionMappings(); - }); + b.HasKey(x => new { x.ApiResourceId, x.Key, x.Value }); - builder.Entity(b => + b.Property(x => x.Key).HasMaxLength(ApiResourcePropertyConsts.KeyMaxLength).IsRequired(); + if (IsDatabaseProvider(builder, EfCoreDatabaseProvider.MySql, EfCoreDatabaseProvider.Oracle)) { - b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ApiResourceProperties", AbpIdentityServerDbProperties.DbSchema); + ApiResourcePropertyConsts.ValueMaxLength = 300; + } + b.Property(x => x.Value).HasMaxLength(ApiResourcePropertyConsts.ValueMaxLength).IsRequired(); - b.ConfigureByConvention(); + b.ApplyObjectExtensionMappings(); + }); - b.HasKey(x => new {x.ApiResourceId, x.Key, x.Value}); + #endregion - b.Property(x => x.Key).HasMaxLength(ApiResourcePropertyConsts.KeyMaxLength).IsRequired(); - if (IsDatabaseProvider(builder, EfCoreDatabaseProvider.MySql, EfCoreDatabaseProvider.Oracle)) - { - ApiResourcePropertyConsts.ValueMaxLength = 300; - } - b.Property(x => x.Value).HasMaxLength(ApiResourcePropertyConsts.ValueMaxLength).IsRequired(); + #region ApiScope - b.ApplyObjectExtensionMappings(); - }); + builder.Entity(b => + { + b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ApiScopes", AbpIdentityServerDbProperties.DbSchema); - #endregion + b.ConfigureByConvention(); - #region ApiScope + 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); - builder.Entity(b => - { - b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ApiScopes", AbpIdentityServerDbProperties.DbSchema); + b.HasMany(x => x.UserClaims).WithOne().HasForeignKey(x => x.ApiScopeId).IsRequired(); + b.HasMany(x => x.Properties).WithOne().HasForeignKey(x => x.ApiScopeId).IsRequired(); - b.ConfigureByConvention(); + b.ApplyObjectExtensionMappings(); + }); - 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); + builder.Entity(b => + { + b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ApiScopeClaims", AbpIdentityServerDbProperties.DbSchema); - b.HasMany(x => x.UserClaims).WithOne().HasForeignKey(x => x.ApiScopeId).IsRequired(); - b.HasMany(x => x.Properties).WithOne().HasForeignKey(x => x.ApiScopeId).IsRequired(); + b.ConfigureByConvention(); - b.ApplyObjectExtensionMappings(); - }); + b.HasKey(x => new { x.ApiScopeId, x.Type }); - builder.Entity(b => - { - b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ApiScopeClaims", AbpIdentityServerDbProperties.DbSchema); + b.Property(x => x.Type).HasMaxLength(UserClaimConsts.TypeMaxLength).IsRequired(); - b.ConfigureByConvention(); + b.ApplyObjectExtensionMappings(); + }); - b.HasKey(x => new {x.ApiScopeId, x.Type}); + builder.Entity(b => + { + b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ApiScopeProperties", AbpIdentityServerDbProperties.DbSchema); - b.Property(x => x.Type).HasMaxLength(UserClaimConsts.TypeMaxLength).IsRequired(); + b.ConfigureByConvention(); - b.ApplyObjectExtensionMappings(); - }); + b.HasKey(x => new { x.ApiScopeId, x.Key, x.Value }); - builder.Entity(b => + b.Property(x => x.Key).HasMaxLength(ApiScopePropertyConsts.KeyMaxLength).IsRequired(); + if (IsDatabaseProvider(builder, EfCoreDatabaseProvider.MySql, EfCoreDatabaseProvider.Oracle)) { - b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "ApiScopeProperties", AbpIdentityServerDbProperties.DbSchema); + ApiScopePropertyConsts.ValueMaxLength = 300; + } + b.Property(x => x.Value).HasMaxLength(ApiScopePropertyConsts.ValueMaxLength).IsRequired(); - b.ConfigureByConvention(); + b.ApplyObjectExtensionMappings(); + }); - b.HasKey(x => new {x.ApiScopeId, x.Key, x.Value}); + #endregion - b.Property(x => x.Key).HasMaxLength(ApiScopePropertyConsts.KeyMaxLength).IsRequired(); - if (IsDatabaseProvider(builder, EfCoreDatabaseProvider.MySql, EfCoreDatabaseProvider.Oracle)) - { - ApiScopePropertyConsts.ValueMaxLength = 300; - } - b.Property(x => x.Value).HasMaxLength(ApiScopePropertyConsts.ValueMaxLength).IsRequired(); + #region PersistedGrant - b.ApplyObjectExtensionMappings(); - }); + builder.Entity(b => + { + b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "PersistedGrants", AbpIdentityServerDbProperties.DbSchema); - #endregion + b.ConfigureByConvention(); - #region PersistedGrant + b.Property(x => x.Key).HasMaxLength(PersistedGrantConsts.KeyMaxLength).ValueGeneratedNever(); + b.Property(x => x.Type).HasMaxLength(PersistedGrantConsts.TypeMaxLength).IsRequired(); + b.Property(x => x.SubjectId).HasMaxLength(PersistedGrantConsts.SubjectIdMaxLength); + b.Property(x => x.SessionId).HasMaxLength(PersistedGrantConsts.SessionIdMaxLength); + b.Property(x => x.ClientId).HasMaxLength(PersistedGrantConsts.ClientIdMaxLength).IsRequired(); + b.Property(x => x.Description).HasMaxLength(PersistedGrantConsts.DescriptionMaxLength); + b.Property(x => x.CreationTime).IsRequired(); - builder.Entity(b => + if (IsDatabaseProvider(builder, EfCoreDatabaseProvider.MySql)) { - b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "PersistedGrants", AbpIdentityServerDbProperties.DbSchema); + PersistedGrantConsts.DataMaxLengthValue = 10000; //TODO: MySQL accepts 20.000. We can consider to change in v3.0. + } - b.ConfigureByConvention(); + b.Property(x => x.Data).HasMaxLength(PersistedGrantConsts.DataMaxLengthValue).IsRequired(); - b.Property(x => x.Key).HasMaxLength(PersistedGrantConsts.KeyMaxLength).ValueGeneratedNever(); - b.Property(x => x.Type).HasMaxLength(PersistedGrantConsts.TypeMaxLength).IsRequired(); - b.Property(x => x.SubjectId).HasMaxLength(PersistedGrantConsts.SubjectIdMaxLength); - b.Property(x => x.SessionId).HasMaxLength(PersistedGrantConsts.SessionIdMaxLength); - b.Property(x => x.ClientId).HasMaxLength(PersistedGrantConsts.ClientIdMaxLength).IsRequired(); - b.Property(x => x.Description).HasMaxLength(PersistedGrantConsts.DescriptionMaxLength); - b.Property(x => x.CreationTime).IsRequired(); + b.HasKey(x => x.Key); //TODO: What about Id!!! - if (IsDatabaseProvider(builder, EfCoreDatabaseProvider.MySql)) - { - PersistedGrantConsts.DataMaxLengthValue = 10000; //TODO: MySQL accepts 20.000. We can consider to change in v3.0. - } + b.HasIndex(x => new { x.SubjectId, x.ClientId, x.Type }); + b.HasIndex(x => new { x.SubjectId, x.SessionId, x.Type }); + b.HasIndex(x => x.Expiration); - b.Property(x => x.Data).HasMaxLength(PersistedGrantConsts.DataMaxLengthValue).IsRequired(); + b.ApplyObjectExtensionMappings(); + }); - b.HasKey(x => x.Key); //TODO: What about Id!!! + #endregion - b.HasIndex(x => new {x.SubjectId, x.ClientId, x.Type}); - b.HasIndex(x => new {x.SubjectId, x.SessionId, x.Type}); - b.HasIndex(x => x.Expiration); + #region DeviceFlowCodes - b.ApplyObjectExtensionMappings(); - }); + builder.Entity(b => + { + b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "DeviceFlowCodes", AbpIdentityServerDbProperties.DbSchema); - #endregion + b.ConfigureByConvention(); - #region DeviceFlowCodes + b.Property(x => x.DeviceCode).HasMaxLength(DeviceFlowCodesConsts.DeviceCodeMaxLength).IsRequired(); + b.Property(x => x.UserCode).HasMaxLength(DeviceFlowCodesConsts.UserCodeMaxLength).IsRequired(); + b.Property(x => x.SubjectId).HasMaxLength(DeviceFlowCodesConsts.SubjectIdMaxLength); + b.Property(x => x.SessionId).HasMaxLength(DeviceFlowCodesConsts.SessionIdMaxLength); + b.Property(x => x.ClientId).HasMaxLength(DeviceFlowCodesConsts.ClientIdMaxLength).IsRequired(); + b.Property(x => x.Description).HasMaxLength(DeviceFlowCodesConsts.DescriptionMaxLength); + b.Property(x => x.CreationTime).IsRequired(); + b.Property(x => x.Expiration).IsRequired(); - builder.Entity(b => + if (IsDatabaseProvider(builder, EfCoreDatabaseProvider.MySql)) { - b.ToTable(AbpIdentityServerDbProperties.DbTablePrefix + "DeviceFlowCodes", AbpIdentityServerDbProperties.DbSchema); - - b.ConfigureByConvention(); - - b.Property(x => x.DeviceCode).HasMaxLength(DeviceFlowCodesConsts.DeviceCodeMaxLength).IsRequired(); - b.Property(x => x.UserCode).HasMaxLength(DeviceFlowCodesConsts.UserCodeMaxLength).IsRequired(); - b.Property(x => x.SubjectId).HasMaxLength(DeviceFlowCodesConsts.SubjectIdMaxLength); - b.Property(x => x.SessionId).HasMaxLength(DeviceFlowCodesConsts.SessionIdMaxLength); - b.Property(x => x.ClientId).HasMaxLength(DeviceFlowCodesConsts.ClientIdMaxLength).IsRequired(); - b.Property(x => x.Description).HasMaxLength(DeviceFlowCodesConsts.DescriptionMaxLength); - b.Property(x => x.CreationTime).IsRequired(); - b.Property(x => x.Expiration).IsRequired(); - - if (IsDatabaseProvider(builder, EfCoreDatabaseProvider.MySql)) - { - DeviceFlowCodesConsts.DataMaxLength = 10000; //TODO: MySQL accepts 20.000. We can consider to change in v3.0. + DeviceFlowCodesConsts.DataMaxLength = 10000; //TODO: MySQL accepts 20.000. We can consider to change in v3.0. } - b.Property(x => x.Data).HasMaxLength(DeviceFlowCodesConsts.DataMaxLength).IsRequired(); + b.Property(x => x.Data).HasMaxLength(DeviceFlowCodesConsts.DataMaxLength).IsRequired(); - b.HasIndex(x => new {x.UserCode}); - b.HasIndex(x => x.DeviceCode).IsUnique(); - b.HasIndex(x => x.Expiration); + b.HasIndex(x => new { x.UserCode }); + b.HasIndex(x => x.DeviceCode).IsUnique(); + b.HasIndex(x => x.Expiration); - b.ApplyObjectExtensionMappings(); - }); + b.ApplyObjectExtensionMappings(); + }); - #endregion + #endregion - builder.TryConfigureObjectExtensions(); - } + builder.TryConfigureObjectExtensions(); + } - private static bool IsDatabaseProvider( - ModelBuilder modelBuilder, - params EfCoreDatabaseProvider[] providers) + private static bool IsDatabaseProvider( + ModelBuilder modelBuilder, + params EfCoreDatabaseProvider[] providers) + { + foreach (var provider in providers) { - foreach (var provider in providers) + if (modelBuilder.GetDatabaseProvider() == provider) { - if (modelBuilder.GetDatabaseProvider() == provider) - { - return true; - } + return true; } - - return false; } + + return false; } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Grants/PersistentGrantRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Grants/PersistentGrantRepository.cs index 8c19d43181..c0417eeda6 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Grants/PersistentGrantRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Grants/PersistentGrantRepository.cs @@ -8,81 +8,80 @@ using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.IdentityServer.EntityFrameworkCore; -namespace Volo.Abp.IdentityServer.Grants +namespace Volo.Abp.IdentityServer.Grants; + +public class PersistentGrantRepository : EfCoreRepository, IPersistentGrantRepository { - public class PersistentGrantRepository : EfCoreRepository, IPersistentGrantRepository + public PersistentGrantRepository(IDbContextProvider dbContextProvider) + : base(dbContextProvider) { - public PersistentGrantRepository(IDbContextProvider dbContextProvider) - : base(dbContextProvider) - { - - } - public async Task> GetListAsync(string subjectId, string sessionId, string clientId, string type, bool includeDetails = false, - CancellationToken cancellationToken = default) - { - return await (await FilterAsync(subjectId, sessionId, clientId, type)) - .ToListAsync(GetCancellationToken(cancellationToken)); - } + } - public virtual async Task FindByKeyAsync( - string key, - CancellationToken cancellationToken = default) - { - return await (await GetDbSetAsync()) - .OrderBy(x => x.Id) - .FirstOrDefaultAsync(x => x.Key == key, GetCancellationToken(cancellationToken)); - } + public async Task> GetListAsync(string subjectId, string sessionId, string clientId, string type, bool includeDetails = false, + CancellationToken cancellationToken = default) + { + return await (await FilterAsync(subjectId, sessionId, clientId, type)) + .ToListAsync(GetCancellationToken(cancellationToken)); + } - public virtual async Task> GetListBySubjectIdAsync( - string subjectId, - CancellationToken cancellationToken = default) - { - return await (await GetDbSetAsync()) - .Where(x => x.SubjectId == subjectId) - .ToListAsync(GetCancellationToken(cancellationToken)); - } + public virtual async Task FindByKeyAsync( + string key, + CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .OrderBy(x => x.Id) + .FirstOrDefaultAsync(x => x.Key == key, GetCancellationToken(cancellationToken)); + } - public virtual async Task> GetListByExpirationAsync( - DateTime maxExpirationDate, - int maxResultCount, - CancellationToken cancellationToken = default) - { - return await (await GetDbSetAsync()) - .Where(x => x.Expiration != null && x.Expiration < maxExpirationDate) - .OrderBy(x => x.ClientId) - .Take(maxResultCount) - .ToListAsync(GetCancellationToken(cancellationToken)); - } + public virtual async Task> GetListBySubjectIdAsync( + string subjectId, + CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .Where(x => x.SubjectId == subjectId) + .ToListAsync(GetCancellationToken(cancellationToken)); + } - public async Task DeleteAsync( - string subjectId = null, - string sessionId = null, - string clientId = null, - string type = null, - CancellationToken cancellationToken = default) - { - var persistedGrants = await (await FilterAsync(subjectId, sessionId, clientId, type)).ToListAsync(GetCancellationToken(cancellationToken)); + public virtual async Task> GetListByExpirationAsync( + DateTime maxExpirationDate, + int maxResultCount, + CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .Where(x => x.Expiration != null && x.Expiration < maxExpirationDate) + .OrderBy(x => x.ClientId) + .Take(maxResultCount) + .ToListAsync(GetCancellationToken(cancellationToken)); + } - var dbSet = await GetDbSetAsync(); + public async Task DeleteAsync( + string subjectId = null, + string sessionId = null, + string clientId = null, + string type = null, + CancellationToken cancellationToken = default) + { + var persistedGrants = await (await FilterAsync(subjectId, sessionId, clientId, type)).ToListAsync(GetCancellationToken(cancellationToken)); - foreach (var persistedGrant in persistedGrants) - { - dbSet.Remove(persistedGrant); - } - } + var dbSet = await GetDbSetAsync(); - private async Task> FilterAsync( - string subjectId, - string sessionId, - string clientId, - string type) + foreach (var persistedGrant in persistedGrants) { - return (await GetDbSetAsync()) - .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); + dbSet.Remove(persistedGrant); } } + + private async Task> FilterAsync( + string subjectId, + string sessionId, + string clientId, + string type) + { + return (await GetDbSetAsync()) + .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); + } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceRepository.cs index 27000c48c4..425a32f970 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceRepository.cs @@ -9,75 +9,74 @@ using Volo.Abp.EntityFrameworkCore; using Volo.Abp.IdentityServer.EntityFrameworkCore; using System.Linq.Dynamic.Core; -namespace Volo.Abp.IdentityServer.IdentityResources +namespace Volo.Abp.IdentityServer.IdentityResources; + +public class IdentityResourceRepository : EfCoreRepository, IIdentityResourceRepository { - public class IdentityResourceRepository : EfCoreRepository, IIdentityResourceRepository + public IdentityResourceRepository(IDbContextProvider dbContextProvider) + : base(dbContextProvider) { - public IdentityResourceRepository(IDbContextProvider dbContextProvider) - : base(dbContextProvider) - { - } + } - public virtual async Task> GetListByScopeNameAsync( - string[] scopeNames, - bool includeDetails = false, - CancellationToken cancellationToken = default) - { - return await (await GetDbSetAsync()) - .IncludeDetails(includeDetails) - .Where(identityResource => scopeNames.Contains(identityResource.Name)) - .ToListAsync(GetCancellationToken(cancellationToken)); - } + public virtual async Task> GetListByScopeNameAsync( + string[] scopeNames, + bool includeDetails = false, + CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .IncludeDetails(includeDetails) + .Where(identityResource => scopeNames.Contains(identityResource.Name)) + .ToListAsync(GetCancellationToken(cancellationToken)); + } - [Obsolete("Use WithDetailsAsync method.")] - public override IQueryable WithDetails() - { - return GetQueryable().IncludeDetails(); - } + [Obsolete("Use WithDetailsAsync method.")] + public override IQueryable WithDetails() + { + return GetQueryable().IncludeDetails(); + } - public override async Task> WithDetailsAsync() - { - return (await GetQueryableAsync()).IncludeDetails(); - } + public override async Task> WithDetailsAsync() + { + return (await GetQueryableAsync()).IncludeDetails(); + } - public virtual async Task> GetListAsync(string sorting, int skipCount, int maxResultCount, - string filter, bool includeDetails = false, CancellationToken cancellationToken = default) - { - return await (await GetDbSetAsync()) - .IncludeDetails(includeDetails) - .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter) || - x.Description.Contains(filter) || - x.DisplayName.Contains(filter)) - .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(IdentityResource.Name) : sorting) - .PageBy(skipCount, maxResultCount) - .ToListAsync(GetCancellationToken(cancellationToken)); - } + public virtual async Task> GetListAsync(string sorting, int skipCount, int maxResultCount, + string filter, bool includeDetails = false, CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .IncludeDetails(includeDetails) + .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter) || + x.Description.Contains(filter) || + x.DisplayName.Contains(filter)) + .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(IdentityResource.Name) : sorting) + .PageBy(skipCount, maxResultCount) + .ToListAsync(GetCancellationToken(cancellationToken)); + } - public async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) - { - return await (await GetDbSetAsync()) - .WhereIf(!filter.IsNullOrWhiteSpace(), - x => x.Name.Contains(filter) || - x.Description.Contains(filter) || - x.DisplayName.Contains(filter)) - .LongCountAsync(GetCancellationToken(cancellationToken)); - } + public async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .WhereIf(!filter.IsNullOrWhiteSpace(), + x => x.Name.Contains(filter) || + x.Description.Contains(filter) || + x.DisplayName.Contains(filter)) + .LongCountAsync(GetCancellationToken(cancellationToken)); + } - public virtual async Task FindByNameAsync( - string name, - bool includeDetails = true, - CancellationToken cancellationToken = default) - { - return await (await GetDbSetAsync()) - .IncludeDetails(includeDetails) - .OrderBy(x => x.Id) - .FirstOrDefaultAsync(x => x.Name == name, GetCancellationToken(cancellationToken)); - } + public virtual async Task FindByNameAsync( + string name, + bool includeDetails = true, + CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .IncludeDetails(includeDetails) + .OrderBy(x => x.Id) + .FirstOrDefaultAsync(x => x.Name == name, GetCancellationToken(cancellationToken)); + } - public virtual async Task CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) - { - return await (await GetDbSetAsync()).AnyAsync(ir => ir.Id != expectedId && ir.Name == name, GetCancellationToken(cancellationToken)); - } + public virtual async Task CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()).AnyAsync(ir => ir.Id != expectedId && ir.Name == name, GetCancellationToken(cancellationToken)); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Installer/Volo/Abp/IdentityServer/AbpIdentityServerInstallerModule.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Installer/Volo/Abp/IdentityServer/AbpIdentityServerInstallerModule.cs index f3b7447744..cbb7f66c1b 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Installer/Volo/Abp/IdentityServer/AbpIdentityServerInstallerModule.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Installer/Volo/Abp/IdentityServer/AbpIdentityServerInstallerModule.cs @@ -2,20 +2,19 @@ using Volo.Abp.Studio; using Volo.Abp.VirtualFileSystem; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +[DependsOn( + typeof(AbpStudioModuleInstallerModule), + typeof(AbpVirtualFileSystemModule) + )] +public class AbpIdentityServerInstallerModule : AbpModule { - [DependsOn( - typeof(AbpStudioModuleInstallerModule), - typeof(AbpVirtualFileSystemModule) - )] - public class AbpIdentityServerInstallerModule : AbpModule + public override void ConfigureServices(ServiceConfigurationContext context) { - public override void ConfigureServices(ServiceConfigurationContext context) + Configure(options => { - Configure(options => - { - options.FileSets.AddEmbedded(); - }); - } + options.FileSets.AddEmbedded(); + }); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Installer/Volo/Abp/IdentityServer/IdentityServerInstallerPipelineBuilder.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Installer/Volo/Abp/IdentityServer/IdentityServerInstallerPipelineBuilder.cs index 02042215f5..76e1692193 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Installer/Volo/Abp/IdentityServer/IdentityServerInstallerPipelineBuilder.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Installer/Volo/Abp/IdentityServer/IdentityServerInstallerPipelineBuilder.cs @@ -3,22 +3,21 @@ using Microsoft.Extensions.DependencyInjection; using Volo.Abp.DependencyInjection; using Volo.Abp.Studio.ModuleInstalling; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +[Dependency(ServiceLifetime.Transient, ReplaceServices = true)] +[ExposeServices(typeof(IModuleInstallingPipelineBuilder))] +public class IdentityServerInstallerPipelineBuilder : ModuleInstallingPipelineBuilderBase, IModuleInstallingPipelineBuilder, ITransientDependency { - [Dependency(ServiceLifetime.Transient, ReplaceServices = true)] - [ExposeServices(typeof(IModuleInstallingPipelineBuilder))] - public class IdentityServerInstallerPipelineBuilder : ModuleInstallingPipelineBuilderBase, IModuleInstallingPipelineBuilder, ITransientDependency + public async Task BuildAsync(ModuleInstallingContext context) { - public async Task BuildAsync(ModuleInstallingContext context) - { - context.AddEfCoreConfigurationMethodDeclaration( - new EfCoreConfigurationMethodDeclaration( - "Volo.Abp.IdentityServer.EntityFrameworkCore", - "ConfigureIdentityServer" - ) - ); - - return GetBasePipeline(context); - } + context.AddEfCoreConfigurationMethodDeclaration( + new EfCoreConfigurationMethodDeclaration( + "Volo.Abp.IdentityServer.EntityFrameworkCore", + "ConfigureIdentityServer" + ) + ); + + return GetBasePipeline(context); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/AbpIdentityServerMongoDbContext.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/AbpIdentityServerMongoDbContext.cs index 49341771ca..3efe009b14 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/AbpIdentityServerMongoDbContext.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/AbpIdentityServerMongoDbContext.cs @@ -9,29 +9,28 @@ using Volo.Abp.IdentityServer.IdentityResources; using Volo.Abp.MongoDB; using Volo.Abp.MultiTenancy; -namespace Volo.Abp.IdentityServer.MongoDB +namespace Volo.Abp.IdentityServer.MongoDB; + +[IgnoreMultiTenancy] +[ConnectionStringName(AbpIdentityServerDbProperties.ConnectionStringName)] +public class AbpIdentityServerMongoDbContext : AbpMongoDbContext, IAbpIdentityServerMongoDbContext { - [IgnoreMultiTenancy] - [ConnectionStringName(AbpIdentityServerDbProperties.ConnectionStringName)] - public class AbpIdentityServerMongoDbContext : AbpMongoDbContext, IAbpIdentityServerMongoDbContext - { - public IMongoCollection ApiResources => Collection(); + public IMongoCollection ApiResources => Collection(); - public IMongoCollection ApiScopes => Collection(); + public IMongoCollection ApiScopes => Collection(); - public IMongoCollection Clients => Collection(); + public IMongoCollection Clients => Collection(); - public IMongoCollection IdentityResources => Collection(); + public IMongoCollection IdentityResources => Collection(); - public IMongoCollection PersistedGrants => Collection(); + public IMongoCollection PersistedGrants => Collection(); - public IMongoCollection DeviceFlowCodes => Collection(); + public IMongoCollection DeviceFlowCodes => Collection(); - protected override void CreateModel(IMongoModelBuilder modelBuilder) - { - base.CreateModel(modelBuilder); + protected override void CreateModel(IMongoModelBuilder modelBuilder) + { + base.CreateModel(modelBuilder); - modelBuilder.ConfigureIdentityServer(); - } + modelBuilder.ConfigureIdentityServer(); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/AbpIdentityServerMongoDbContextExtensions.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/AbpIdentityServerMongoDbContextExtensions.cs index ea3d2e40c9..3aca58158d 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/AbpIdentityServerMongoDbContextExtensions.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/AbpIdentityServerMongoDbContextExtensions.cs @@ -6,44 +6,43 @@ using Volo.Abp.IdentityServer.Grants; using Volo.Abp.IdentityServer.IdentityResources; using Volo.Abp.MongoDB; -namespace Volo.Abp.IdentityServer.MongoDB +namespace Volo.Abp.IdentityServer.MongoDB; + +public static class AbpIdentityServerMongoDbContextExtensions { - public static class AbpIdentityServerMongoDbContextExtensions + public static void ConfigureIdentityServer( + this IMongoModelBuilder builder) { - public static void ConfigureIdentityServer( - this IMongoModelBuilder builder) + Check.NotNull(builder, nameof(builder)); + + builder.Entity(b => + { + b.CollectionName = AbpIdentityServerDbProperties.DbTablePrefix + "ApiResources"; + }); + + builder.Entity(b => + { + b.CollectionName = AbpIdentityServerDbProperties.DbTablePrefix + "ApiScopes"; + }); + + builder.Entity(b => + { + b.CollectionName = AbpIdentityServerDbProperties.DbTablePrefix + "IdentityResources"; + }); + + builder.Entity(b => + { + b.CollectionName = AbpIdentityServerDbProperties.DbTablePrefix + "Clients"; + }); + + builder.Entity(b => + { + b.CollectionName = AbpIdentityServerDbProperties.DbTablePrefix + "PersistedGrants"; + }); + + builder.Entity(b => { - Check.NotNull(builder, nameof(builder)); - - builder.Entity(b => - { - b.CollectionName = AbpIdentityServerDbProperties.DbTablePrefix + "ApiResources"; - }); - - builder.Entity(b => - { - b.CollectionName = AbpIdentityServerDbProperties.DbTablePrefix + "ApiScopes"; - }); - - builder.Entity(b => - { - b.CollectionName = AbpIdentityServerDbProperties.DbTablePrefix + "IdentityResources"; - }); - - builder.Entity(b => - { - b.CollectionName = AbpIdentityServerDbProperties.DbTablePrefix + "Clients"; - }); - - builder.Entity(b => - { - b.CollectionName = AbpIdentityServerDbProperties.DbTablePrefix + "PersistedGrants"; - }); - - builder.Entity(b => - { - b.CollectionName = AbpIdentityServerDbProperties.DbTablePrefix + "DeviceFlowCodes"; - }); - } + b.CollectionName = AbpIdentityServerDbProperties.DbTablePrefix + "DeviceFlowCodes"; + }); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/AbpIdentityServerMongoDbModule.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/AbpIdentityServerMongoDbModule.cs index 6cd13aac37..bd43bbe5d1 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/AbpIdentityServerMongoDbModule.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/AbpIdentityServerMongoDbModule.cs @@ -8,35 +8,34 @@ using Volo.Abp.IdentityServer.IdentityResources; using Volo.Abp.Modularity; using Volo.Abp.MongoDB; -namespace Volo.Abp.IdentityServer.MongoDB +namespace Volo.Abp.IdentityServer.MongoDB; + +[DependsOn( + typeof(AbpIdentityServerDomainModule), + typeof(AbpMongoDbModule) +)] +public class AbpIdentityServerMongoDbModule : AbpModule { - [DependsOn( - typeof(AbpIdentityServerDomainModule), - typeof(AbpMongoDbModule) - )] - public class AbpIdentityServerMongoDbModule : AbpModule + public override void PreConfigureServices(ServiceConfigurationContext context) { - public override void PreConfigureServices(ServiceConfigurationContext context) - { - context.Services.PreConfigure( - builder => - { - builder.AddAbpStores(); - } - ); - } + context.Services.PreConfigure( + builder => + { + builder.AddAbpStores(); + } + ); + } - public override void ConfigureServices(ServiceConfigurationContext context) + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services.AddMongoDbContext(options => { - context.Services.AddMongoDbContext(options => - { - options.AddRepository(); - options.AddRepository(); - options.AddRepository(); - options.AddRepository(); - options.AddRepository(); - options.AddRepository(); - }); - } + options.AddRepository(); + options.AddRepository(); + options.AddRepository(); + options.AddRepository(); + options.AddRepository(); + options.AddRepository(); + }); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/IAbpIdentityServerMongoDbContext.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/IAbpIdentityServerMongoDbContext.cs index ad9c90b62c..33079dc6f2 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/IAbpIdentityServerMongoDbContext.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/IAbpIdentityServerMongoDbContext.cs @@ -9,22 +9,21 @@ using Volo.Abp.IdentityServer.IdentityResources; using Volo.Abp.MongoDB; using Volo.Abp.MultiTenancy; -namespace Volo.Abp.IdentityServer.MongoDB +namespace Volo.Abp.IdentityServer.MongoDB; + +[IgnoreMultiTenancy] +[ConnectionStringName(AbpIdentityServerDbProperties.ConnectionStringName)] +public interface IAbpIdentityServerMongoDbContext : IAbpMongoDbContext { - [IgnoreMultiTenancy] - [ConnectionStringName(AbpIdentityServerDbProperties.ConnectionStringName)] - public interface IAbpIdentityServerMongoDbContext : IAbpMongoDbContext - { - IMongoCollection ApiResources { get; } + IMongoCollection ApiResources { get; } - IMongoCollection ApiScopes { get; } + IMongoCollection ApiScopes { get; } - IMongoCollection Clients { get; } + IMongoCollection Clients { get; } - IMongoCollection IdentityResources { get; } + IMongoCollection IdentityResources { get; } - IMongoCollection PersistedGrants { get; } + IMongoCollection PersistedGrants { get; } - IMongoCollection DeviceFlowCodes { get; } - } + IMongoCollection DeviceFlowCodes { get; } } 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 56b58d674d..af0f63ae0f 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 @@ -10,65 +10,64 @@ using System.Linq.Dynamic.Core; using Volo.Abp.IdentityServer.ApiResources; using Volo.Abp.MongoDB; -namespace Volo.Abp.IdentityServer.MongoDB +namespace Volo.Abp.IdentityServer.MongoDB; + +public class MongoApiResourceRepository : MongoDbRepository, IApiResourceRepository { - public class MongoApiResourceRepository : MongoDbRepository, IApiResourceRepository + public MongoApiResourceRepository(IMongoDbContextProvider dbContextProvider) : base(dbContextProvider) { - public MongoApiResourceRepository(IMongoDbContextProvider dbContextProvider) : base(dbContextProvider) - { - } - - public async Task FindByNameAsync(string apiResourceName, bool includeDetails = true, CancellationToken cancellationToken = default) - { - return await (await GetMongoQueryableAsync(cancellationToken)) - .OrderBy(ar => ar.Id) - .FirstOrDefaultAsync(ar => ar.Name == apiResourceName, GetCancellationToken(cancellationToken)); - } + } - public async Task> FindByNameAsync(string[] apiResourceNames, bool includeDetails = true, - CancellationToken cancellationToken = default) - { - return await (await GetMongoQueryableAsync(cancellationToken)) - .Where(ar => apiResourceNames.Contains(ar.Name)) - .ToListAsync(GetCancellationToken(cancellationToken)); - } + public async Task FindByNameAsync(string apiResourceName, bool includeDetails = true, CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync(cancellationToken)) + .OrderBy(ar => ar.Id) + .FirstOrDefaultAsync(ar => ar.Name == apiResourceName, GetCancellationToken(cancellationToken)); + } - public virtual async Task> GetListByScopesAsync(string[] scopeNames, bool includeDetails = false, - CancellationToken cancellationToken = default) - { - return await (await GetMongoQueryableAsync(cancellationToken)) - .Where(ar => ar.Scopes.Any(x => scopeNames.Contains(x.Scope))) - .ToListAsync(GetCancellationToken(cancellationToken)); - } + public async Task> FindByNameAsync(string[] apiResourceNames, bool includeDetails = true, + CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync(cancellationToken)) + .Where(ar => apiResourceNames.Contains(ar.Name)) + .ToListAsync(GetCancellationToken(cancellationToken)); + } - public virtual async Task> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter, bool includeDetails = false, - CancellationToken cancellationToken = default) - { - return await (await GetMongoQueryableAsync(cancellationToken)) - .WhereIf(!filter.IsNullOrWhiteSpace(), - x => x.Name.Contains(filter) || - x.Description.Contains(filter) || - x.DisplayName.Contains(filter)) - .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(ApiResource.Name) : sorting) - .As>() - .PageBy>(skipCount, maxResultCount) - .ToListAsync(GetCancellationToken(cancellationToken)); - } + public virtual async Task> GetListByScopesAsync(string[] scopeNames, bool includeDetails = false, + CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync(cancellationToken)) + .Where(ar => ar.Scopes.Any(x => scopeNames.Contains(x.Scope))) + .ToListAsync(GetCancellationToken(cancellationToken)); + } - public async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) - { - return await (await GetMongoQueryableAsync(cancellationToken)) - .WhereIf>(!filter.IsNullOrWhiteSpace(), - x => x.Name.Contains(filter) || + public virtual async Task> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter, bool includeDetails = false, + CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync(cancellationToken)) + .WhereIf(!filter.IsNullOrWhiteSpace(), + x => x.Name.Contains(filter) || x.Description.Contains(filter) || x.DisplayName.Contains(filter)) - .LongCountAsync(GetCancellationToken(cancellationToken)); - } + .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(ApiResource.Name) : sorting) + .As>() + .PageBy>(skipCount, maxResultCount) + .ToListAsync(GetCancellationToken(cancellationToken)); + } - public virtual async Task CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) - { - return await (await GetMongoQueryableAsync(cancellationToken)) - .AnyAsync(ar => ar.Id != expectedId && ar.Name == name, GetCancellationToken(cancellationToken)); - } + public async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync(cancellationToken)) + .WhereIf>(!filter.IsNullOrWhiteSpace(), + x => x.Name.Contains(filter) || + x.Description.Contains(filter) || + x.DisplayName.Contains(filter)) + .LongCountAsync(GetCancellationToken(cancellationToken)); + } + + public virtual async Task CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync(cancellationToken)) + .AnyAsync(ar => ar.Id != expectedId && ar.Name == name, GetCancellationToken(cancellationToken)); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiScopeRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiScopeRepository.cs index da78505c82..eddd300909 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiScopeRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoApiScopeRepository.cs @@ -10,60 +10,59 @@ using Volo.Abp.IdentityServer.ApiScopes; using System.Linq.Dynamic.Core; using Volo.Abp.MongoDB; -namespace Volo.Abp.IdentityServer.MongoDB +namespace Volo.Abp.IdentityServer.MongoDB; + +public class MongoApiScopeRepository : MongoDbRepository, + IApiScopeRepository { - public class MongoApiScopeRepository : MongoDbRepository, - IApiScopeRepository + public MongoApiScopeRepository(IMongoDbContextProvider dbContextProvider) : + base(dbContextProvider) { - public MongoApiScopeRepository(IMongoDbContextProvider dbContextProvider) : - base(dbContextProvider) - { - } + } - public async Task FindByNameAsync(string scopeName, bool includeDetails = true, CancellationToken cancellationToken = default) - { - return await (await GetMongoQueryableAsync(cancellationToken)) - .OrderBy(x => x.Id) - .FirstOrDefaultAsync(x => x.Name == scopeName, GetCancellationToken(cancellationToken)); - } + public async Task FindByNameAsync(string scopeName, bool includeDetails = true, CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync(cancellationToken)) + .OrderBy(x => x.Id) + .FirstOrDefaultAsync(x => x.Name == scopeName, GetCancellationToken(cancellationToken)); + } - public async Task> GetListByNameAsync(string[] scopeNames, bool includeDetails = false, - CancellationToken cancellationToken = default) - { - return await (await GetMongoQueryableAsync(cancellationToken)) - .Where(scope => scopeNames.Contains(scope.Name)) - .OrderBy(scope => scope.Id) - .ToListAsync(GetCancellationToken(cancellationToken)); - } + public async Task> GetListByNameAsync(string[] scopeNames, bool includeDetails = false, + CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync(cancellationToken)) + .Where(scope => scopeNames.Contains(scope.Name)) + .OrderBy(scope => scope.Id) + .ToListAsync(GetCancellationToken(cancellationToken)); + } - public async Task> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter = null, bool includeDetails = false, - CancellationToken cancellationToken = default) - { - return await (await GetMongoQueryableAsync(cancellationToken)) - .WhereIf(!filter.IsNullOrWhiteSpace(), - x => x.Name.Contains(filter) || - x.Description.Contains(filter) || - x.DisplayName.Contains(filter)) - .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(ApiScope.Name) : sorting) - .As>() - .PageBy>(skipCount, maxResultCount) - .ToListAsync(GetCancellationToken(cancellationToken)); - } + public async Task> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter = null, bool includeDetails = false, + CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync(cancellationToken)) + .WhereIf(!filter.IsNullOrWhiteSpace(), + x => x.Name.Contains(filter) || + x.Description.Contains(filter) || + x.DisplayName.Contains(filter)) + .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(ApiScope.Name) : sorting) + .As>() + .PageBy>(skipCount, maxResultCount) + .ToListAsync(GetCancellationToken(cancellationToken)); + } - public async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) - { - return await (await GetMongoQueryableAsync(cancellationToken)) - .WhereIf>(!filter.IsNullOrWhiteSpace(), - x => x.Name.Contains(filter) || - x.Description.Contains(filter) || - x.DisplayName.Contains(filter)) - .LongCountAsync(GetCancellationToken(cancellationToken)); - } + public async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync(cancellationToken)) + .WhereIf>(!filter.IsNullOrWhiteSpace(), + x => x.Name.Contains(filter) || + x.Description.Contains(filter) || + x.DisplayName.Contains(filter)) + .LongCountAsync(GetCancellationToken(cancellationToken)); + } - public async Task CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) - { - return await (await GetMongoQueryableAsync(cancellationToken)) - .AnyAsync(x => x.Id != expectedId && x.Name == name, GetCancellationToken(cancellationToken)); - } + public async Task CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync(cancellationToken)) + .AnyAsync(x => x.Id != expectedId && x.Name == name, GetCancellationToken(cancellationToken)); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoClientRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoClientRepository.cs index 694f5ace25..3a6be89c8f 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoClientRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoClientRepository.cs @@ -10,65 +10,64 @@ using System.Linq.Dynamic.Core; using Volo.Abp.IdentityServer.Clients; using Volo.Abp.MongoDB; -namespace Volo.Abp.IdentityServer.MongoDB +namespace Volo.Abp.IdentityServer.MongoDB; + +public class MongoClientRepository : MongoDbRepository, IClientRepository { - public class MongoClientRepository : MongoDbRepository, IClientRepository + public MongoClientRepository( + IMongoDbContextProvider dbContextProvider + ) : base( + dbContextProvider) { - public MongoClientRepository( - IMongoDbContextProvider dbContextProvider - ) : base( - dbContextProvider) - { - } + } - public virtual async Task FindByClientIdAsync( - string clientId, - bool includeDetails = true, - CancellationToken cancellationToken = default) - { - return await (await GetMongoQueryableAsync(cancellationToken)) - .OrderBy(x => x.Id) - .FirstOrDefaultAsync(x => x.ClientId == clientId, GetCancellationToken(cancellationToken)); - } + public virtual async Task FindByClientIdAsync( + string clientId, + bool includeDetails = true, + CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync(cancellationToken)) + .OrderBy(x => x.Id) + .FirstOrDefaultAsync(x => x.ClientId == clientId, GetCancellationToken(cancellationToken)); + } - public virtual async Task> GetListAsync( - string sorting, - int skipCount, - int maxResultCount, - string filter = null, - bool includeDetails = false, - CancellationToken cancellationToken = default) - { - return await (await GetMongoQueryableAsync(cancellationToken)) - .WhereIf(!filter.IsNullOrWhiteSpace(), x=>x.ClientId.Contains(filter)) - .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(Client.ClientName) : sorting) - .As>() - .PageBy>(skipCount, maxResultCount) - .ToListAsync(GetCancellationToken(cancellationToken)); - } + public virtual async Task> GetListAsync( + string sorting, + int skipCount, + int maxResultCount, + string filter = null, + bool includeDetails = false, + CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync(cancellationToken)) + .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.ClientId.Contains(filter)) + .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(Client.ClientName) : sorting) + .As>() + .PageBy>(skipCount, maxResultCount) + .ToListAsync(GetCancellationToken(cancellationToken)); + } - public async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) - { - return await (await GetMongoQueryableAsync(cancellationToken)) - .WhereIf>(!filter.IsNullOrWhiteSpace(), - x => x.ClientId.Contains(filter)) - .LongCountAsync(GetCancellationToken(cancellationToken)); - } + public async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync(cancellationToken)) + .WhereIf>(!filter.IsNullOrWhiteSpace(), + x => x.ClientId.Contains(filter)) + .LongCountAsync(GetCancellationToken(cancellationToken)); + } - public virtual async Task> GetAllDistinctAllowedCorsOriginsAsync( - CancellationToken cancellationToken = default) - { - return await (await GetMongoQueryableAsync(cancellationToken)) - .SelectMany(x => x.AllowedCorsOrigins) - .Select(y => y.Origin) - .Distinct() - .ToListAsync(GetCancellationToken(cancellationToken)); - } + public virtual async Task> GetAllDistinctAllowedCorsOriginsAsync( + CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync(cancellationToken)) + .SelectMany(x => x.AllowedCorsOrigins) + .Select(y => y.Origin) + .Distinct() + .ToListAsync(GetCancellationToken(cancellationToken)); + } - public virtual async Task CheckClientIdExistAsync(string clientId, Guid? expectedId = null, CancellationToken cancellationToken = default) - { - return await (await GetMongoQueryableAsync(cancellationToken)) - .AnyAsync(c => c.Id != expectedId && c.ClientId == clientId, GetCancellationToken(cancellationToken)); - } + public virtual async Task CheckClientIdExistAsync(string clientId, Guid? expectedId = null, CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync(cancellationToken)) + .AnyAsync(c => c.Id != expectedId && c.ClientId == clientId, GetCancellationToken(cancellationToken)); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoDeviceFlowCodesRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoDeviceFlowCodesRepository.cs index 83e87c0a58..1b7e9519ae 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoDeviceFlowCodesRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoDeviceFlowCodesRepository.cs @@ -8,45 +8,44 @@ using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.IdentityServer.Devices; using Volo.Abp.MongoDB; -namespace Volo.Abp.IdentityServer.MongoDB +namespace Volo.Abp.IdentityServer.MongoDB; + +public class MongoDeviceFlowCodesRepository : + MongoDbRepository, IDeviceFlowCodesRepository { - public class MongoDeviceFlowCodesRepository : - MongoDbRepository, IDeviceFlowCodesRepository + public MongoDeviceFlowCodesRepository( + IMongoDbContextProvider dbContextProvider) : base(dbContextProvider) { - public MongoDeviceFlowCodesRepository( - IMongoDbContextProvider dbContextProvider) : base(dbContextProvider) - { - } + } - public virtual async Task FindByUserCodeAsync( - string userCode, - CancellationToken cancellationToken = default) - { - return await (await GetMongoQueryableAsync(cancellationToken)) - .Where(d => d.UserCode == userCode) - .OrderBy(x => x.Id) - .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); - } + public virtual async Task FindByUserCodeAsync( + string userCode, + CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync(cancellationToken)) + .Where(d => d.UserCode == userCode) + .OrderBy(x => x.Id) + .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); + } - public virtual async Task FindByDeviceCodeAsync(string deviceCode, CancellationToken cancellationToken = default) - { - return await (await GetMongoQueryableAsync(cancellationToken)) - .Where(d => d.DeviceCode == deviceCode) - .OrderBy(x => x.Id) - .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); - } + public virtual async Task FindByDeviceCodeAsync(string deviceCode, CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync(cancellationToken)) + .Where(d => d.DeviceCode == deviceCode) + .OrderBy(x => x.Id) + .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); + } - public virtual async Task> GetListByExpirationAsync( - DateTime maxExpirationDate, - int maxResultCount, - CancellationToken cancellationToken = default) - { - return await (await GetMongoQueryableAsync(cancellationToken)) - .Where(x => x.Expiration != null && x.Expiration < maxExpirationDate) - .OrderBy(x => x.ClientId) - .Take(maxResultCount) - .ToListAsync(GetCancellationToken(cancellationToken)); - } + public virtual async Task> GetListByExpirationAsync( + DateTime maxExpirationDate, + int maxResultCount, + CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync(cancellationToken)) + .Where(x => x.Expiration != null && x.Expiration < maxExpirationDate) + .OrderBy(x => x.ClientId) + .Take(maxResultCount) + .ToListAsync(GetCancellationToken(cancellationToken)); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoIdentityResourceRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoIdentityResourceRepository.cs index e63ca82188..b60077644b 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoIdentityResourceRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoIdentityResourceRepository.cs @@ -10,59 +10,58 @@ using Volo.Abp.IdentityServer.IdentityResources; using Volo.Abp.MongoDB; using System.Linq.Dynamic.Core; -namespace Volo.Abp.IdentityServer.MongoDB +namespace Volo.Abp.IdentityServer.MongoDB; + +public class MongoIdentityResourceRepository : MongoDbRepository, IIdentityResourceRepository { - public class MongoIdentityResourceRepository : MongoDbRepository, IIdentityResourceRepository + public MongoIdentityResourceRepository(IMongoDbContextProvider dbContextProvider) : base(dbContextProvider) { - public MongoIdentityResourceRepository(IMongoDbContextProvider dbContextProvider) : base(dbContextProvider) - { - } + } - public virtual async Task> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter, bool includeDetails = false, CancellationToken cancellationToken = default) - { - return await (await GetMongoQueryableAsync(cancellationToken)) - .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter) || - x.Description.Contains(filter) || - x.DisplayName.Contains(filter)) - .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(IdentityResource.Name) : sorting) - .As>() - .PageBy>(skipCount, maxResultCount) - .ToListAsync(GetCancellationToken(cancellationToken)); - } + public virtual async Task> GetListAsync(string sorting, int skipCount, int maxResultCount, string filter, bool includeDetails = false, CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync(cancellationToken)) + .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter) || + x.Description.Contains(filter) || + x.DisplayName.Contains(filter)) + .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(IdentityResource.Name) : sorting) + .As>() + .PageBy>(skipCount, maxResultCount) + .ToListAsync(GetCancellationToken(cancellationToken)); + } - public async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) - { - return await (await GetMongoQueryableAsync(cancellationToken)) - .WhereIf>(!filter.IsNullOrWhiteSpace(), - x => x.Name.Contains(filter) || - x.Description.Contains(filter) || - x.DisplayName.Contains(filter)) - .LongCountAsync(GetCancellationToken(cancellationToken)); - } + public async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync(cancellationToken)) + .WhereIf>(!filter.IsNullOrWhiteSpace(), + x => x.Name.Contains(filter) || + x.Description.Contains(filter) || + x.DisplayName.Contains(filter)) + .LongCountAsync(GetCancellationToken(cancellationToken)); + } - public virtual async Task FindByNameAsync( - string name, - bool includeDetails = true, - CancellationToken cancellationToken = default) - { - return await (await GetMongoQueryableAsync(cancellationToken)) - .Where(x => x.Name == name) - .OrderBy(x => x.Id) - .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); - } + public virtual async Task FindByNameAsync( + string name, + bool includeDetails = true, + CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync(cancellationToken)) + .Where(x => x.Name == name) + .OrderBy(x => x.Id) + .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); + } - public virtual async Task> GetListByScopeNameAsync(string[] scopeNames, bool includeDetails = false, - CancellationToken cancellationToken = default) - { - return await (await GetMongoQueryableAsync(cancellationToken)) - .Where(ar => scopeNames.Contains(ar.Name)) - .ToListAsync(GetCancellationToken(cancellationToken)); - } + public virtual async Task> GetListByScopeNameAsync(string[] scopeNames, bool includeDetails = false, + CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync(cancellationToken)) + .Where(ar => scopeNames.Contains(ar.Name)) + .ToListAsync(GetCancellationToken(cancellationToken)); + } - public virtual async Task CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) - { - return await (await GetMongoQueryableAsync(cancellationToken)) - .AnyAsync(ir => ir.Id != expectedId && ir.Name == name, GetCancellationToken(cancellationToken)); - } + public virtual async Task CheckNameExistAsync(string name, Guid? expectedId = null, CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync(cancellationToken)) + .AnyAsync(ir => ir.Id != expectedId && ir.Name == name, GetCancellationToken(cancellationToken)); } } diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoPersistentGrantRepository.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoPersistentGrantRepository.cs index 9dd4f24af6..8836e6d53e 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoPersistentGrantRepository.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.MongoDB/Volo/Abp/IdentityServer/MongoDB/MongoPersistentGrantRepository.cs @@ -10,91 +10,90 @@ using Volo.Abp.IdentityServer.Grants; using Volo.Abp.MongoDB; -namespace Volo.Abp.IdentityServer.MongoDB +namespace Volo.Abp.IdentityServer.MongoDB; + +public class MongoPersistentGrantRepository : MongoDbRepository, IPersistentGrantRepository { - public class MongoPersistentGrantRepository : MongoDbRepository, IPersistentGrantRepository + public MongoPersistentGrantRepository(IMongoDbContextProvider dbContextProvider) : base(dbContextProvider) { - public MongoPersistentGrantRepository(IMongoDbContextProvider dbContextProvider) : base(dbContextProvider) - { - } - - public async Task> GetListAsync(string subjectId, string sessionId, string clientId, string type, bool includeDetails = false, - CancellationToken cancellationToken = default) - { - return await (await FilterAsync(subjectId, sessionId, clientId, type, cancellationToken)) - .ToListAsync(GetCancellationToken(cancellationToken)); - } + } - public virtual async Task FindByKeyAsync(string key, CancellationToken cancellationToken = default) - { - return await (await GetMongoQueryableAsync(cancellationToken)) - .Where(x => x.Key == key) - .OrderBy(x => x.Id) - .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); - } + public async Task> GetListAsync(string subjectId, string sessionId, string clientId, string type, bool includeDetails = false, + CancellationToken cancellationToken = default) + { + return await (await FilterAsync(subjectId, sessionId, clientId, type, cancellationToken)) + .ToListAsync(GetCancellationToken(cancellationToken)); + } - public virtual async Task> GetListBySubjectIdAsync(string subjectId, CancellationToken cancellationToken = default) - { - return await (await GetMongoQueryableAsync(cancellationToken)) - .Where(x => x.SubjectId == subjectId) - .ToListAsync(GetCancellationToken(cancellationToken)); - } + public virtual async Task FindByKeyAsync(string key, CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync(cancellationToken)) + .Where(x => x.Key == key) + .OrderBy(x => x.Id) + .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); + } - public virtual async Task> GetListByExpirationAsync(DateTime maxExpirationDate, int maxResultCount, - CancellationToken cancellationToken = default) - { - return await (await GetMongoQueryableAsync(cancellationToken)) - .Where(x => x.Expiration != null && x.Expiration < maxExpirationDate) - .OrderBy(x => x.ClientId) - .Take(maxResultCount) - .ToListAsync(GetCancellationToken(cancellationToken)); - } + public virtual async Task> GetListBySubjectIdAsync(string subjectId, CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync(cancellationToken)) + .Where(x => x.SubjectId == subjectId) + .ToListAsync(GetCancellationToken(cancellationToken)); + } - public async Task DeleteAsync( - string subjectId = null, - string sessionId = null, - string clientId = null, - string type = null, - CancellationToken cancellationToken = default) - { - var persistedGrants = await (await FilterAsync(subjectId, sessionId, clientId, type, cancellationToken)) - .ToListAsync(GetCancellationToken(cancellationToken)); + public virtual async Task> GetListByExpirationAsync(DateTime maxExpirationDate, int maxResultCount, + CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync(cancellationToken)) + .Where(x => x.Expiration != null && x.Expiration < maxExpirationDate) + .OrderBy(x => x.ClientId) + .Take(maxResultCount) + .ToListAsync(GetCancellationToken(cancellationToken)); + } - foreach (var persistedGrant in persistedGrants) - { - await DeleteAsync(persistedGrant, false, GetCancellationToken(cancellationToken)); - } - } + public async Task DeleteAsync( + string subjectId = null, + string sessionId = null, + string clientId = null, + string type = null, + CancellationToken cancellationToken = default) + { + var persistedGrants = await (await FilterAsync(subjectId, sessionId, clientId, type, cancellationToken)) + .ToListAsync(GetCancellationToken(cancellationToken)); - public virtual async Task DeleteAsync(string subjectId, string clientId, CancellationToken cancellationToken = default) + foreach (var persistedGrant in persistedGrants) { - await DeleteAsync( - x => x.SubjectId == subjectId && x.ClientId == clientId, - cancellationToken: GetCancellationToken(cancellationToken) - ); + await DeleteAsync(persistedGrant, false, GetCancellationToken(cancellationToken)); } + } - public virtual async Task DeleteAsync(string subjectId, string clientId, string type, CancellationToken cancellationToken = default) - { - await DeleteAsync( - x => x.SubjectId == subjectId && x.ClientId == clientId && x.Type == type, - cancellationToken: GetCancellationToken(cancellationToken) - ); - } + public virtual async Task DeleteAsync(string subjectId, string clientId, CancellationToken cancellationToken = default) + { + await DeleteAsync( + x => x.SubjectId == subjectId && x.ClientId == clientId, + cancellationToken: GetCancellationToken(cancellationToken) + ); + } - private async Task> FilterAsync( - string subjectId, - string sessionId, - string clientId, - string type, - CancellationToken cancellationToken = default) - { - return (await GetMongoQueryableAsync(cancellationToken)) - .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>(); - } + public virtual async Task DeleteAsync(string subjectId, string clientId, string type, CancellationToken cancellationToken = default) + { + await DeleteAsync( + x => x.SubjectId == subjectId && x.ClientId == clientId && x.Type == type, + cancellationToken: GetCancellationToken(cancellationToken) + ); + } + + private async Task> FilterAsync( + string subjectId, + string sessionId, + string clientId, + string type, + CancellationToken cancellationToken = default) + { + return (await GetMongoQueryableAsync(cancellationToken)) + .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/src/Volo.Abp.PermissionManagement.Domain.IdentityServer/Volo/Abp/PermissionManagement/IdentityServer/AbpPermissionManagementDomainIdentityServerModule.cs b/modules/identityserver/src/Volo.Abp.PermissionManagement.Domain.IdentityServer/Volo/Abp/PermissionManagement/IdentityServer/AbpPermissionManagementDomainIdentityServerModule.cs index b078221c5e..3d2d42c28f 100644 --- a/modules/identityserver/src/Volo.Abp.PermissionManagement.Domain.IdentityServer/Volo/Abp/PermissionManagement/IdentityServer/AbpPermissionManagementDomainIdentityServerModule.cs +++ b/modules/identityserver/src/Volo.Abp.PermissionManagement.Domain.IdentityServer/Volo/Abp/PermissionManagement/IdentityServer/AbpPermissionManagementDomainIdentityServerModule.cs @@ -2,22 +2,21 @@ using Volo.Abp.IdentityServer; using Volo.Abp.Modularity; -namespace Volo.Abp.PermissionManagement.IdentityServer +namespace Volo.Abp.PermissionManagement.IdentityServer; + +[DependsOn( + typeof(AbpIdentityServerDomainSharedModule), + typeof(AbpPermissionManagementDomainModule) +)] +public class AbpPermissionManagementDomainIdentityServerModule : AbpModule { - [DependsOn( - typeof(AbpIdentityServerDomainSharedModule), - typeof(AbpPermissionManagementDomainModule) - )] - public class AbpPermissionManagementDomainIdentityServerModule : AbpModule + public override void ConfigureServices(ServiceConfigurationContext context) { - public override void ConfigureServices(ServiceConfigurationContext context) + Configure(options => { - Configure(options => - { - options.ManagementProviders.Add(); + options.ManagementProviders.Add(); - options.ProviderPolicies[ClientPermissionValueProvider.ProviderName] = "IdentityServer.Client.ManagePermissions"; - }); - } + options.ProviderPolicies[ClientPermissionValueProvider.ProviderName] = "IdentityServer.Client.ManagePermissions"; + }); } } diff --git a/modules/identityserver/src/Volo.Abp.PermissionManagement.Domain.IdentityServer/Volo/Abp/PermissionManagement/IdentityServer/ClientPermissionManagementProvider.cs b/modules/identityserver/src/Volo.Abp.PermissionManagement.Domain.IdentityServer/Volo/Abp/PermissionManagement/IdentityServer/ClientPermissionManagementProvider.cs index 15d9952c74..dd25c6d5c0 100644 --- a/modules/identityserver/src/Volo.Abp.PermissionManagement.Domain.IdentityServer/Volo/Abp/PermissionManagement/IdentityServer/ClientPermissionManagementProvider.cs +++ b/modules/identityserver/src/Volo.Abp.PermissionManagement.Domain.IdentityServer/Volo/Abp/PermissionManagement/IdentityServer/ClientPermissionManagementProvider.cs @@ -3,54 +3,53 @@ using Volo.Abp.Authorization.Permissions; using Volo.Abp.Guids; using Volo.Abp.MultiTenancy; -namespace Volo.Abp.PermissionManagement.IdentityServer +namespace Volo.Abp.PermissionManagement.IdentityServer; + +public class ClientPermissionManagementProvider : PermissionManagementProvider { - public class ClientPermissionManagementProvider : PermissionManagementProvider + public override string Name => ClientPermissionValueProvider.ProviderName; + + public ClientPermissionManagementProvider( + IPermissionGrantRepository permissionGrantRepository, + IGuidGenerator guidGenerator, + ICurrentTenant currentTenant) + : base( + permissionGrantRepository, + guidGenerator, + currentTenant) { - public override string Name => ClientPermissionValueProvider.ProviderName; - - public ClientPermissionManagementProvider( - IPermissionGrantRepository permissionGrantRepository, - IGuidGenerator guidGenerator, - ICurrentTenant currentTenant) - : base( - permissionGrantRepository, - guidGenerator, - currentTenant) - { - } + } - public override Task CheckAsync(string name, string providerName, string providerKey) + public override Task CheckAsync(string name, string providerName, string providerKey) + { + using (CurrentTenant.Change(null)) { - using (CurrentTenant.Change(null)) - { - return base.CheckAsync(name, providerName, providerKey); - } + return base.CheckAsync(name, providerName, providerKey); } + } - protected override Task GrantAsync(string name, string providerKey) + protected override Task GrantAsync(string name, string providerKey) + { + using (CurrentTenant.Change(null)) { - using (CurrentTenant.Change(null)) - { - return base.GrantAsync(name, providerKey); - } + return base.GrantAsync(name, providerKey); } + } - protected override Task RevokeAsync(string name, string providerKey) + protected override Task RevokeAsync(string name, string providerKey) + { + using (CurrentTenant.Change(null)) { - using (CurrentTenant.Change(null)) - { - return base.RevokeAsync(name, providerKey); - } + return base.RevokeAsync(name, providerKey); } + } - public override Task SetAsync(string name, string providerKey, bool isGranted) + public override Task SetAsync(string name, string providerKey, bool isGranted) + { + using (CurrentTenant.Change(null)) { - using (CurrentTenant.Change(null)) - { - return base.SetAsync(name, providerKey, isGranted); - } + return base.SetAsync(name, providerKey, isGranted); } } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/AbpClientConfigurationValidator_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/AbpClientConfigurationValidator_Tests.cs index 1c145b4f1e..beb718a909 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/AbpClientConfigurationValidator_Tests.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/AbpClientConfigurationValidator_Tests.cs @@ -6,47 +6,46 @@ using Microsoft.Extensions.DependencyInjection; using Shouldly; using Xunit; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class AbpClientConfigurationValidator_Tests : AbpIdentityServerTestBase { - public class AbpClientConfigurationValidator_Tests : AbpIdentityServerTestBase - { - private readonly IClientConfigurationValidator _abpClientConfigurationValidator; + private readonly IClientConfigurationValidator _abpClientConfigurationValidator; - private readonly Client _testClient = new Client - { - AllowedGrantTypes = GrantTypes.Code, + private readonly Client _testClient = new Client + { + AllowedGrantTypes = GrantTypes.Code, - ClientSecrets = new List() + ClientSecrets = new List() { new IdentityServer4.Models.Secret("1q2w3e*") }, - RedirectUris = new List + RedirectUris = new List { "https://{0}.api.abp.io:8080", "http://{0}.ng.abp.io", "http://ng.abp.io" } - }; + }; - public AbpClientConfigurationValidator_Tests() - { - _abpClientConfigurationValidator = GetRequiredService(); - } + public AbpClientConfigurationValidator_Tests() + { + _abpClientConfigurationValidator = GetRequiredService(); + } - protected override void AfterAddApplication(IServiceCollection services) - { - services.AddAbpClientConfigurationValidator(); - } + protected override void AfterAddApplication(IServiceCollection services) + { + services.AddAbpClientConfigurationValidator(); + } - [Fact] - public async Task ValidateAsync() - { - var context = new ClientConfigurationValidationContext(_testClient); + [Fact] + public async Task ValidateAsync() + { + var context = new ClientConfigurationValidationContext(_testClient); - await _abpClientConfigurationValidator.ValidateAsync(context); + await _abpClientConfigurationValidator.ValidateAsync(context); - context.IsValid.ShouldBeTrue(); - } + context.IsValid.ShouldBeTrue(); } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/AbpIdentityServerDomainTestBase.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/AbpIdentityServerDomainTestBase.cs index 5b9c9240bf..9442976b9a 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/AbpIdentityServerDomainTestBase.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/AbpIdentityServerDomainTestBase.cs @@ -1,12 +1,11 @@ using Volo.Abp.Testing; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class AbpIdentityServerDomainTestBase : AbpIntegratedTest { - public class AbpIdentityServerDomainTestBase : AbpIntegratedTest + protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) { - protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) - { - options.UseAutofac(); - } + options.UseAutofac(); } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/AbpIdentityServerDomainTestModule.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/AbpIdentityServerDomainTestModule.cs index e219427d03..ac5a48a28f 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/AbpIdentityServerDomainTestModule.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/AbpIdentityServerDomainTestModule.cs @@ -1,10 +1,9 @@ using Volo.Abp.Modularity; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +[DependsOn(typeof(AbpIdentityServerTestEntityFrameworkCoreModule))] +public class AbpIdentityServerDomainTestModule : AbpModule { - [DependsOn(typeof(AbpIdentityServerTestEntityFrameworkCoreModule))] - public class AbpIdentityServerDomainTestModule : AbpModule - { - } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/AbpStrictRedirectUriValidator_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/AbpStrictRedirectUriValidator_Tests.cs index 7f00d2e355..9abd83a8d5 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/AbpStrictRedirectUriValidator_Tests.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/AbpStrictRedirectUriValidator_Tests.cs @@ -6,70 +6,69 @@ using Microsoft.Extensions.DependencyInjection; using Shouldly; using Xunit; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class AbpStrictRedirectUriValidator_Tests : AbpIdentityServerTestBase { - public class AbpStrictRedirectUriValidator_Tests : AbpIdentityServerTestBase - { - private readonly IRedirectUriValidator _abpStrictRedirectUriValidator; + private readonly IRedirectUriValidator _abpStrictRedirectUriValidator; - private readonly Client _testClient = new Client - { - RedirectUris = new List + private readonly Client _testClient = new Client + { + RedirectUris = new List { "https://{0}.api.abp.io:8080/signin-oidc", "http://{0}.ng.abp.io/index.html" }, - PostLogoutRedirectUris = new List + PostLogoutRedirectUris = new List { "https://{0}.api.abp.io:8080/signin-oidc", "http://{0}.ng.abp.io/index.html" } - }; + }; - public AbpStrictRedirectUriValidator_Tests() - { - _abpStrictRedirectUriValidator = GetRequiredService(); - } + public AbpStrictRedirectUriValidator_Tests() + { + _abpStrictRedirectUriValidator = GetRequiredService(); + } - protected override void AfterAddApplication(IServiceCollection services) - { - services.AddAbpStrictRedirectUriValidator(); - } + protected override void AfterAddApplication(IServiceCollection services) + { + services.AddAbpStrictRedirectUriValidator(); + } - [Fact] - public void Should_Register_AbpStrictRedirectUriValidator() - { - _abpStrictRedirectUriValidator.GetType().ShouldBe(typeof(AbpStrictRedirectUriValidator)); - } + [Fact] + public void Should_Register_AbpStrictRedirectUriValidator() + { + _abpStrictRedirectUriValidator.GetType().ShouldBe(typeof(AbpStrictRedirectUriValidator)); + } - [Fact] - public async Task IsRedirectUriValidAsync() - { - (await _abpStrictRedirectUriValidator.IsRedirectUriValidAsync("https://t1.api.abp.io:8080/signin-oidc", _testClient)).ShouldBeTrue(); - (await _abpStrictRedirectUriValidator.IsRedirectUriValidAsync("https://api.abp.io:8080/signin-oidc", _testClient)).ShouldBeTrue(); - (await _abpStrictRedirectUriValidator.IsRedirectUriValidAsync("http://t2.ng.abp.io/index.html", _testClient)).ShouldBeTrue(); - (await _abpStrictRedirectUriValidator.IsRedirectUriValidAsync("http://ng.abp.io/index.html", _testClient)).ShouldBeTrue(); + [Fact] + public async Task IsRedirectUriValidAsync() + { + (await _abpStrictRedirectUriValidator.IsRedirectUriValidAsync("https://t1.api.abp.io:8080/signin-oidc", _testClient)).ShouldBeTrue(); + (await _abpStrictRedirectUriValidator.IsRedirectUriValidAsync("https://api.abp.io:8080/signin-oidc", _testClient)).ShouldBeTrue(); + (await _abpStrictRedirectUriValidator.IsRedirectUriValidAsync("http://t2.ng.abp.io/index.html", _testClient)).ShouldBeTrue(); + (await _abpStrictRedirectUriValidator.IsRedirectUriValidAsync("http://ng.abp.io/index.html", _testClient)).ShouldBeTrue(); - (await _abpStrictRedirectUriValidator.IsRedirectUriValidAsync("https://api.abp:8080/", _testClient)).ShouldBeFalse(); - (await _abpStrictRedirectUriValidator.IsRedirectUriValidAsync("http://ng.abp.io", _testClient)).ShouldBeTrue(); - (await _abpStrictRedirectUriValidator.IsRedirectUriValidAsync("https://api.t1.abp:8080/", _testClient)).ShouldBeFalse(); - (await _abpStrictRedirectUriValidator.IsRedirectUriValidAsync("http://ng.t1.abp.io", _testClient)).ShouldBeFalse(); - (await _abpStrictRedirectUriValidator.IsRedirectUriValidAsync("http://t1.ng.abp.io/index.html.mydomain.com", _testClient)).ShouldBeFalse(); - } + (await _abpStrictRedirectUriValidator.IsRedirectUriValidAsync("https://api.abp:8080/", _testClient)).ShouldBeFalse(); + (await _abpStrictRedirectUriValidator.IsRedirectUriValidAsync("http://ng.abp.io", _testClient)).ShouldBeTrue(); + (await _abpStrictRedirectUriValidator.IsRedirectUriValidAsync("https://api.t1.abp:8080/", _testClient)).ShouldBeFalse(); + (await _abpStrictRedirectUriValidator.IsRedirectUriValidAsync("http://ng.t1.abp.io", _testClient)).ShouldBeFalse(); + (await _abpStrictRedirectUriValidator.IsRedirectUriValidAsync("http://t1.ng.abp.io/index.html.mydomain.com", _testClient)).ShouldBeFalse(); + } - [Fact] - public async Task IsPostLogoutRedirectUriValidAsync() - { - (await _abpStrictRedirectUriValidator.IsPostLogoutRedirectUriValidAsync("https://t1.api.abp.io:8080/signin-oidc", _testClient)).ShouldBeTrue(); - (await _abpStrictRedirectUriValidator.IsPostLogoutRedirectUriValidAsync("https://api.abp.io:8080/signin-oidc", _testClient)).ShouldBeTrue(); - (await _abpStrictRedirectUriValidator.IsPostLogoutRedirectUriValidAsync("http://t2.ng.abp.io/index.html", _testClient)).ShouldBeTrue(); - (await _abpStrictRedirectUriValidator.IsPostLogoutRedirectUriValidAsync("http://ng.abp.io/index.html", _testClient)).ShouldBeTrue(); + [Fact] + public async Task IsPostLogoutRedirectUriValidAsync() + { + (await _abpStrictRedirectUriValidator.IsPostLogoutRedirectUriValidAsync("https://t1.api.abp.io:8080/signin-oidc", _testClient)).ShouldBeTrue(); + (await _abpStrictRedirectUriValidator.IsPostLogoutRedirectUriValidAsync("https://api.abp.io:8080/signin-oidc", _testClient)).ShouldBeTrue(); + (await _abpStrictRedirectUriValidator.IsPostLogoutRedirectUriValidAsync("http://t2.ng.abp.io/index.html", _testClient)).ShouldBeTrue(); + (await _abpStrictRedirectUriValidator.IsPostLogoutRedirectUriValidAsync("http://ng.abp.io/index.html", _testClient)).ShouldBeTrue(); - (await _abpStrictRedirectUriValidator.IsPostLogoutRedirectUriValidAsync("https://api.abp:8080/", _testClient)).ShouldBeFalse(); - (await _abpStrictRedirectUriValidator.IsPostLogoutRedirectUriValidAsync("http://ng.abp.io", _testClient)).ShouldBeTrue(); - (await _abpStrictRedirectUriValidator.IsPostLogoutRedirectUriValidAsync("https://api.t1.abp:8080/", _testClient)).ShouldBeFalse(); - (await _abpStrictRedirectUriValidator.IsPostLogoutRedirectUriValidAsync("http://ng.t1.abp.io", _testClient)).ShouldBeFalse(); - (await _abpStrictRedirectUriValidator.IsPostLogoutRedirectUriValidAsync("http://t1.ng.abp.io/index.html.mydomain.com", _testClient)).ShouldBeFalse(); - } + (await _abpStrictRedirectUriValidator.IsPostLogoutRedirectUriValidAsync("https://api.abp:8080/", _testClient)).ShouldBeFalse(); + (await _abpStrictRedirectUriValidator.IsPostLogoutRedirectUriValidAsync("http://ng.abp.io", _testClient)).ShouldBeTrue(); + (await _abpStrictRedirectUriValidator.IsPostLogoutRedirectUriValidAsync("https://api.t1.abp:8080/", _testClient)).ShouldBeFalse(); + (await _abpStrictRedirectUriValidator.IsPostLogoutRedirectUriValidAsync("http://ng.t1.abp.io", _testClient)).ShouldBeFalse(); + (await _abpStrictRedirectUriValidator.IsPostLogoutRedirectUriValidAsync("http://t1.ng.abp.io/index.html.mydomain.com", _testClient)).ShouldBeFalse(); } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/AbpWildcardSubdomainCorsPolicyService_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/AbpWildcardSubdomainCorsPolicyService_Tests.cs index 36949582d7..74fc65291f 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/AbpWildcardSubdomainCorsPolicyService_Tests.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/AbpWildcardSubdomainCorsPolicyService_Tests.cs @@ -4,39 +4,38 @@ using Microsoft.Extensions.DependencyInjection; using Shouldly; using Xunit; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class AbpWildcardSubdomainCorsPolicyService_Tests : AbpIdentityServerTestBase { - public class AbpWildcardSubdomainCorsPolicyService_Tests : AbpIdentityServerTestBase + private readonly ICorsPolicyService _corsPolicyService; + + public AbpWildcardSubdomainCorsPolicyService_Tests() { - private readonly ICorsPolicyService _corsPolicyService; - - public AbpWildcardSubdomainCorsPolicyService_Tests() - { - _corsPolicyService = GetRequiredService(); - } - - protected override void AfterAddApplication(IServiceCollection services) - { - services.AddAbpWildcardSubdomainCorsPolicyService(); - } - - [Fact] - public void Should_Register_AbpWildcardSubdomainCorsPolicyService() - { - _corsPolicyService.GetType().ShouldBe(typeof(AbpWildcardSubdomainCorsPolicyService)); - } - - [Fact] - public async Task IsOriginAllowedAsync() - { - (await _corsPolicyService.IsOriginAllowedAsync("https://client1-origin.com")).ShouldBeTrue(); - (await _corsPolicyService.IsOriginAllowedAsync("https://client2-origin.com")).ShouldBeFalse(); - - (await _corsPolicyService.IsOriginAllowedAsync("https://abp.io")).ShouldBeTrue(); - (await _corsPolicyService.IsOriginAllowedAsync("https://t1.abp.io")).ShouldBeTrue(); - (await _corsPolicyService.IsOriginAllowedAsync("https://t1.ng.abp.io")).ShouldBeTrue(); - - (await _corsPolicyService.IsOriginAllowedAsync("https://t1.abp.io.mydomain.com")).ShouldBeFalse(); - } + _corsPolicyService = GetRequiredService(); + } + + protected override void AfterAddApplication(IServiceCollection services) + { + services.AddAbpWildcardSubdomainCorsPolicyService(); + } + + [Fact] + public void Should_Register_AbpWildcardSubdomainCorsPolicyService() + { + _corsPolicyService.GetType().ShouldBe(typeof(AbpWildcardSubdomainCorsPolicyService)); + } + + [Fact] + public async Task IsOriginAllowedAsync() + { + (await _corsPolicyService.IsOriginAllowedAsync("https://client1-origin.com")).ShouldBeTrue(); + (await _corsPolicyService.IsOriginAllowedAsync("https://client2-origin.com")).ShouldBeFalse(); + + (await _corsPolicyService.IsOriginAllowedAsync("https://abp.io")).ShouldBeTrue(); + (await _corsPolicyService.IsOriginAllowedAsync("https://t1.abp.io")).ShouldBeTrue(); + (await _corsPolicyService.IsOriginAllowedAsync("https://t1.ng.abp.io")).ShouldBeTrue(); + + (await _corsPolicyService.IsOriginAllowedAsync("https://t1.abp.io.mydomain.com")).ShouldBeFalse(); } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Cache/IdentityServerCacheItemInvalidator_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Cache/IdentityServerCacheItemInvalidator_Tests.cs index ba1b026fa0..6d0b8a3b19 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Cache/IdentityServerCacheItemInvalidator_Tests.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Cache/IdentityServerCacheItemInvalidator_Tests.cs @@ -14,125 +14,124 @@ using ApiScope = IdentityServer4.Models.ApiScope; using Client = IdentityServer4.Models.Client; using IdentityResource = IdentityServer4.Models.IdentityResource; -namespace Volo.Abp.IdentityServer.Cache +namespace Volo.Abp.IdentityServer.Cache; + +public class IdentityServerCacheItemInvalidator_Tests : AbpIdentityServerTestBase { - public class IdentityServerCacheItemInvalidator_Tests : AbpIdentityServerTestBase + private readonly IClientStore _clientStore; + private readonly IResourceStore _resourceStore; + + private readonly IClientRepository _clientRepository; + private readonly IIdentityResourceRepository _identityResourceRepository; + private readonly IApiResourceRepository _apiResourceRepository; + private readonly IApiScopeRepository _apiScopeRepository; + + private readonly IDistributedCache _clientCache; + private readonly IDistributedCache _identityResourceCache; + private readonly IDistributedCache _apiResourceCache; + private readonly IDistributedCache _apiScopeCache; + private readonly IDistributedCache _resourceCache; + + private readonly AbpIdentityServerTestData _testData; + + public IdentityServerCacheItemInvalidator_Tests() { - private readonly IClientStore _clientStore; - private readonly IResourceStore _resourceStore; - - private readonly IClientRepository _clientRepository; - private readonly IIdentityResourceRepository _identityResourceRepository; - private readonly IApiResourceRepository _apiResourceRepository; - private readonly IApiScopeRepository _apiScopeRepository; - - private readonly IDistributedCache _clientCache; - private readonly IDistributedCache _identityResourceCache; - private readonly IDistributedCache_apiResourceCache; - private readonly IDistributedCache _apiScopeCache; - private readonly IDistributedCache _resourceCache; - - private readonly AbpIdentityServerTestData _testData; - - public IdentityServerCacheItemInvalidator_Tests() - { - _clientStore = GetRequiredService(); - _resourceStore = GetRequiredService(); - - _clientRepository = GetRequiredService(); - _identityResourceRepository = GetRequiredService(); - _apiResourceRepository = GetRequiredService(); - _apiScopeRepository = GetRequiredService(); - - _clientCache = GetRequiredService>(); - _identityResourceCache = GetRequiredService>(); - _apiResourceCache = GetRequiredService>(); - _apiScopeCache = GetRequiredService>(); - _resourceCache = GetRequiredService>(); - - _testData = GetRequiredService(); - } - - [Fact] - public async Task Models_Should_Cached_And_Invalidator_When_Its_Changed() - { - //client - var clientId = "ClientId1"; - (await _clientCache.GetAsync(clientId)).ShouldBeNull(); - - var client = await _clientStore.FindClientByIdAsync(clientId); - client.ShouldNotBeNull(); - - var clientCacheItem = await _clientCache.GetAsync(clientId); - clientCacheItem.ShouldNotBeNull(); - - await _clientRepository.DeleteAsync(_testData.Client1Id); - (await _clientCache.GetAsync(clientId)).ShouldBeNull(); - - - //Api Resource - var newApiResource1 = "NewApiResource1"; - var newApiResource2 = "NewApiResource2"; - var testApiResourceName1 = "Test-ApiResource-Name-1"; - var testApiResourceApiScopeName1 = "Test-ApiResource-ApiScope-Name-1"; - var newApiResources = new[] {newApiResource1, newApiResource2}; - - //FindApiResourcesByNameAsync - (await _apiResourceCache.GetAsync(newApiResource1)).ShouldBeNull(); - (await _apiResourceCache.GetAsync(newApiResource2)).ShouldBeNull(); - await _resourceStore.FindApiResourcesByNameAsync(newApiResources); - (await _apiResourceCache.GetAsync(ResourceStore.ApiResourceNameCacheKeyPrefix + newApiResource1)).ShouldNotBeNull(); - (await _apiResourceCache.GetAsync(ResourceStore.ApiResourceNameCacheKeyPrefix + newApiResource2)).ShouldNotBeNull(); - - var apiResource1 = await _apiResourceRepository.FindByNameAsync(newApiResource1); - await _apiResourceRepository.DeleteAsync(apiResource1); - (await _apiResourceCache.GetAsync(newApiResource1)).ShouldBeNull(); - - var apiResource2 = await _apiResourceRepository.FindByNameAsync(newApiResource2); - await _apiResourceRepository.DeleteAsync(apiResource2); - (await _apiResourceCache.GetAsync(newApiResource2)).ShouldBeNull(); - - //FindApiResourcesByScopeNameAsync - (await _apiResourceCache.GetAsync(ResourceStore.ApiResourceScopeNameCacheKeyPrefix + testApiResourceApiScopeName1)).ShouldBeNull(); - await _resourceStore.FindApiResourcesByScopeNameAsync(new []{ testApiResourceApiScopeName1 }); - (await _apiResourceCache.GetAsync(ResourceStore.ApiResourceScopeNameCacheKeyPrefix + testApiResourceApiScopeName1)).ShouldNotBeNull(); - - var testApiResource1 = await _apiResourceRepository.FindByNameAsync(testApiResourceName1); - await _apiResourceRepository.DeleteAsync(testApiResource1); - (await _apiResourceCache.GetAsync(ResourceStore.ApiResourceScopeNameCacheKeyPrefix + testApiResourceApiScopeName1)).ShouldBeNull(); - - - //Identity Resource - var testIdentityResourceName = "Test-Identity-Resource-Name-1"; - var testIdentityResourceNames = new[] {testIdentityResourceName}; - (await _identityResourceCache.GetAsync(testIdentityResourceName)).ShouldBeNull(); - await _resourceStore.FindIdentityResourcesByScopeNameAsync(testIdentityResourceNames); - (await _identityResourceCache.GetAsync(testIdentityResourceName)).ShouldNotBeNull(); - - var testIdentityResource = await _identityResourceRepository.FindByNameAsync(testIdentityResourceName); - await _identityResourceRepository.DeleteAsync(testIdentityResource); - (await _identityResourceCache.GetAsync(testIdentityResourceName)).ShouldBeNull(); - - - //Api Scope - var testApiScopeName = "Test-ApiScope-Name-1"; - var testApiScopeNames = new[] {testApiScopeName}; - (await _apiScopeCache.GetAsync(testApiScopeName)).ShouldBeNull(); - await _resourceStore.FindApiScopesByNameAsync(testApiScopeNames); - (await _apiScopeCache.GetAsync(testApiScopeName)).ShouldNotBeNull(); - - var testApiScope = await _apiScopeRepository.FindByNameAsync(testApiScopeName); - await _apiScopeRepository.DeleteAsync(testApiScope); - (await _apiScopeCache.GetAsync(testApiScopeName)).ShouldBeNull(); - - - //Resources - (await _resourceCache.GetAsync(ResourceStore.AllResourcesKey)).ShouldBeNull(); - await _resourceStore.GetAllResourcesAsync(); - (await _resourceCache.GetAsync(ResourceStore.AllResourcesKey)).ShouldNotBeNull(); - - await _identityResourceRepository.DeleteAsync(_testData.IdentityResource1Id); - (await _resourceCache.GetAsync(ResourceStore.AllResourcesKey)).ShouldBeNull(); - } + _clientStore = GetRequiredService(); + _resourceStore = GetRequiredService(); + + _clientRepository = GetRequiredService(); + _identityResourceRepository = GetRequiredService(); + _apiResourceRepository = GetRequiredService(); + _apiScopeRepository = GetRequiredService(); + + _clientCache = GetRequiredService>(); + _identityResourceCache = GetRequiredService>(); + _apiResourceCache = GetRequiredService>(); + _apiScopeCache = GetRequiredService>(); + _resourceCache = GetRequiredService>(); + + _testData = GetRequiredService(); + } + + [Fact] + public async Task Models_Should_Cached_And_Invalidator_When_Its_Changed() + { + //client + var clientId = "ClientId1"; + (await _clientCache.GetAsync(clientId)).ShouldBeNull(); + + var client = await _clientStore.FindClientByIdAsync(clientId); + client.ShouldNotBeNull(); + + var clientCacheItem = await _clientCache.GetAsync(clientId); + clientCacheItem.ShouldNotBeNull(); + + await _clientRepository.DeleteAsync(_testData.Client1Id); + (await _clientCache.GetAsync(clientId)).ShouldBeNull(); + + + //Api Resource + var newApiResource1 = "NewApiResource1"; + var newApiResource2 = "NewApiResource2"; + var testApiResourceName1 = "Test-ApiResource-Name-1"; + var testApiResourceApiScopeName1 = "Test-ApiResource-ApiScope-Name-1"; + var newApiResources = new[] { newApiResource1, newApiResource2 }; + + //FindApiResourcesByNameAsync + (await _apiResourceCache.GetAsync(newApiResource1)).ShouldBeNull(); + (await _apiResourceCache.GetAsync(newApiResource2)).ShouldBeNull(); + await _resourceStore.FindApiResourcesByNameAsync(newApiResources); + (await _apiResourceCache.GetAsync(ResourceStore.ApiResourceNameCacheKeyPrefix + newApiResource1)).ShouldNotBeNull(); + (await _apiResourceCache.GetAsync(ResourceStore.ApiResourceNameCacheKeyPrefix + newApiResource2)).ShouldNotBeNull(); + + var apiResource1 = await _apiResourceRepository.FindByNameAsync(newApiResource1); + await _apiResourceRepository.DeleteAsync(apiResource1); + (await _apiResourceCache.GetAsync(newApiResource1)).ShouldBeNull(); + + var apiResource2 = await _apiResourceRepository.FindByNameAsync(newApiResource2); + await _apiResourceRepository.DeleteAsync(apiResource2); + (await _apiResourceCache.GetAsync(newApiResource2)).ShouldBeNull(); + + //FindApiResourcesByScopeNameAsync + (await _apiResourceCache.GetAsync(ResourceStore.ApiResourceScopeNameCacheKeyPrefix + testApiResourceApiScopeName1)).ShouldBeNull(); + await _resourceStore.FindApiResourcesByScopeNameAsync(new[] { testApiResourceApiScopeName1 }); + (await _apiResourceCache.GetAsync(ResourceStore.ApiResourceScopeNameCacheKeyPrefix + testApiResourceApiScopeName1)).ShouldNotBeNull(); + + var testApiResource1 = await _apiResourceRepository.FindByNameAsync(testApiResourceName1); + await _apiResourceRepository.DeleteAsync(testApiResource1); + (await _apiResourceCache.GetAsync(ResourceStore.ApiResourceScopeNameCacheKeyPrefix + testApiResourceApiScopeName1)).ShouldBeNull(); + + + //Identity Resource + var testIdentityResourceName = "Test-Identity-Resource-Name-1"; + var testIdentityResourceNames = new[] { testIdentityResourceName }; + (await _identityResourceCache.GetAsync(testIdentityResourceName)).ShouldBeNull(); + await _resourceStore.FindIdentityResourcesByScopeNameAsync(testIdentityResourceNames); + (await _identityResourceCache.GetAsync(testIdentityResourceName)).ShouldNotBeNull(); + + var testIdentityResource = await _identityResourceRepository.FindByNameAsync(testIdentityResourceName); + await _identityResourceRepository.DeleteAsync(testIdentityResource); + (await _identityResourceCache.GetAsync(testIdentityResourceName)).ShouldBeNull(); + + + //Api Scope + var testApiScopeName = "Test-ApiScope-Name-1"; + var testApiScopeNames = new[] { testApiScopeName }; + (await _apiScopeCache.GetAsync(testApiScopeName)).ShouldBeNull(); + await _resourceStore.FindApiScopesByNameAsync(testApiScopeNames); + (await _apiScopeCache.GetAsync(testApiScopeName)).ShouldNotBeNull(); + + var testApiScope = await _apiScopeRepository.FindByNameAsync(testApiScopeName); + await _apiScopeRepository.DeleteAsync(testApiScope); + (await _apiScopeCache.GetAsync(testApiScopeName)).ShouldBeNull(); + + + //Resources + (await _resourceCache.GetAsync(ResourceStore.AllResourcesKey)).ShouldBeNull(); + await _resourceStore.GetAllResourcesAsync(); + (await _resourceCache.GetAsync(ResourceStore.AllResourcesKey)).ShouldNotBeNull(); + + await _identityResourceRepository.DeleteAsync(_testData.IdentityResource1Id); + (await _resourceCache.GetAsync(ResourceStore.AllResourcesKey)).ShouldBeNull(); } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Clients/ClientStore_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Clients/ClientStore_Tests.cs index 326edfd4ac..0a213eb93d 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Clients/ClientStore_Tests.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Clients/ClientStore_Tests.cs @@ -4,36 +4,35 @@ using Microsoft.Extensions.DependencyInjection; using Shouldly; using Xunit; -namespace Volo.Abp.IdentityServer.Clients +namespace Volo.Abp.IdentityServer.Clients; + +public class ClientStore_Tests : AbpIdentityServerTestBase { - public class ClientStore_Tests : AbpIdentityServerTestBase - { - private readonly IClientStore _clientStore; + private readonly IClientStore _clientStore; - public ClientStore_Tests() - { - _clientStore = ServiceProvider.GetRequiredService(); - } + public ClientStore_Tests() + { + _clientStore = ServiceProvider.GetRequiredService(); + } - [Fact] - public async Task FindClientByIdAsync_Should_Return_Null_If_Not_Found() - { - var client = await _clientStore.FindClientByIdAsync("non-existing-id"); - client.ShouldBeNull(); - } + [Fact] + public async Task FindClientByIdAsync_Should_Return_Null_If_Not_Found() + { + var client = await _clientStore.FindClientByIdAsync("non-existing-id"); + client.ShouldBeNull(); + } - [Fact] - public async Task FindClientByIdAsync_Should_Return_The_Client_If_Found() - { - //Act - var client = await _clientStore.FindClientByIdAsync("42"); + [Fact] + public async Task FindClientByIdAsync_Should_Return_The_Client_If_Found() + { + //Act + var client = await _clientStore.FindClientByIdAsync("42"); - //Assert - client.ShouldNotBeNull(); - client.ClientId.ShouldBe("42"); - client.ProtocolType.ShouldBe("TestProtocol-42"); - client.AllowedCorsOrigins.ShouldContain("Origin1"); - client.AllowedScopes.ShouldContain("Test-ApiScope-Name-1"); - } + //Assert + client.ShouldNotBeNull(); + client.ClientId.ShouldBe("42"); + client.ProtocolType.ShouldBe("TestProtocol-42"); + client.AllowedCorsOrigins.ShouldContain("Origin1"); + client.AllowedScopes.ShouldContain("Test-ApiScope-Name-1"); } } 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 fcbb937bc4..7d946b012c 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 @@ -7,81 +7,80 @@ using Microsoft.Extensions.DependencyInjection; using Shouldly; using Xunit; -namespace Volo.Abp.IdentityServer.Clients +namespace Volo.Abp.IdentityServer.Clients; + +public class IdentityResourceStore_Tests : AbpIdentityServerTestBase { - public class IdentityResourceStore_Tests : AbpIdentityServerTestBase - { - private readonly IResourceStore _resourceStore; + private readonly IResourceStore _resourceStore; - public IdentityResourceStore_Tests() - { - _resourceStore = ServiceProvider.GetRequiredService(); - } + public IdentityResourceStore_Tests() + { + _resourceStore = ServiceProvider.GetRequiredService(); + } - [Fact] - public async Task FindApiResourceAsync_Should_Return_Empty_If_Not_Found() - { - //Act - var resource = await _resourceStore.FindApiResourcesByNameAsync(new []{"non-existing-name"}); + [Fact] + public async Task FindApiResourceAsync_Should_Return_Empty_If_Not_Found() + { + //Act + var resource = await _resourceStore.FindApiResourcesByNameAsync(new[] { "non-existing-name" }); - //Assert - resource.ShouldBeEmpty(); - } + //Assert + resource.ShouldBeEmpty(); + } - [Fact] - public async Task FindApiResourceAsync_Should_Return_If_Found() - { - //Act - var apiResource = (await _resourceStore.FindApiResourcesByNameAsync(new []{"Test-ApiResource-Name-1"})).FirstOrDefault(); + [Fact] + public async Task FindApiResourceAsync_Should_Return_If_Found() + { + //Act + var apiResource = (await _resourceStore.FindApiResourcesByNameAsync(new[] { "Test-ApiResource-Name-1" })).FirstOrDefault(); - //Assert - apiResource.ShouldNotBe(null); - apiResource.Name.ShouldBe("Test-ApiResource-Name-1"); - apiResource.Description.ShouldBe("Test-ApiResource-Description-1"); - apiResource.DisplayName.ShouldBe("Test-ApiResource-DisplayName-1"); - } + //Assert + apiResource.ShouldNotBe(null); + apiResource.Name.ShouldBe("Test-ApiResource-Name-1"); + apiResource.Description.ShouldBe("Test-ApiResource-Description-1"); + apiResource.DisplayName.ShouldBe("Test-ApiResource-DisplayName-1"); + } - [Fact] - public async Task FindApiResourcesByScopeAsync_Should_Return_If_Found() - { - //Act - var apiResources = (await _resourceStore.FindApiResourcesByScopeNameAsync(new List + [Fact] + public async Task FindApiResourcesByScopeAsync_Should_Return_If_Found() + { + //Act + var apiResources = (await _resourceStore.FindApiResourcesByScopeNameAsync(new List { "Test-ApiResource-ApiScope-Name-1" })).ToList(); - //Assert - apiResources.ShouldNotBe(null); + //Assert + apiResources.ShouldNotBe(null); - apiResources[0].Scopes.Count.ShouldBe(3); - } + apiResources[0].Scopes.Count.ShouldBe(3); + } - [Fact] - public async Task FindIdentityResourcesByScopeAsync_Should_Return_For_Given_Scopes() - { - //Act - var identityResourcesByScope = (await _resourceStore.FindIdentityResourcesByScopeNameAsync(new List + [Fact] + public async Task FindIdentityResourcesByScopeAsync_Should_Return_For_Given_Scopes() + { + //Act + var identityResourcesByScope = (await _resourceStore.FindIdentityResourcesByScopeNameAsync(new List { "Test-Identity-Resource-Name-1" })).ToArray(); - //Assert - identityResourcesByScope.Length.ShouldBe(1); - identityResourcesByScope.First().DisplayName.ShouldBe("Test-Identity-Resource-DisplayName-1"); - identityResourcesByScope.First().Description.ShouldBe("Test-Identity-Resource-Description-1"); - identityResourcesByScope.First().Required.ShouldBe(true); - } + //Assert + identityResourcesByScope.Length.ShouldBe(1); + identityResourcesByScope.First().DisplayName.ShouldBe("Test-Identity-Resource-DisplayName-1"); + identityResourcesByScope.First().Description.ShouldBe("Test-Identity-Resource-Description-1"); + identityResourcesByScope.First().Required.ShouldBe(true); + } - [Fact] - public async Task GetAllResourcesAsync_Should_Return() - { - //Act - var resources = await _resourceStore.GetAllResourcesAsync(); + [Fact] + public async Task GetAllResourcesAsync_Should_Return() + { + //Act + var resources = await _resourceStore.GetAllResourcesAsync(); - //Assert - resources.ShouldNotBe(null); - resources.ApiResources.Count.ShouldBeGreaterThan(0); - resources.ApiResources.Any(r => r.Name == "Test-ApiResource-Name-1").ShouldBeTrue(); - } + //Assert + resources.ShouldNotBe(null); + resources.ApiResources.Count.ShouldBeGreaterThan(0); + resources.ApiResources.Any(r => r.Name == "Test-ApiResource-Name-1").ShouldBeTrue(); } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Clients/PersistentGrant_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Clients/PersistentGrant_Tests.cs index c5848ec7de..547a7c1920 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Clients/PersistentGrant_Tests.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Clients/PersistentGrant_Tests.cs @@ -7,181 +7,180 @@ using Microsoft.Extensions.DependencyInjection; using Shouldly; using Xunit; -namespace Volo.Abp.IdentityServer.Clients +namespace Volo.Abp.IdentityServer.Clients; + +public class PersistentGrantStore_Tests : AbpIdentityServerTestBase { - public class PersistentGrantStore_Tests : AbpIdentityServerTestBase + private readonly IPersistedGrantStore _persistedGrantStore; + + public PersistentGrantStore_Tests() { - private readonly IPersistedGrantStore _persistedGrantStore; + _persistedGrantStore = ServiceProvider.GetRequiredService(); + } - public PersistentGrantStore_Tests() - { - _persistedGrantStore = ServiceProvider.GetRequiredService(); - } + [Fact] + public async Task FindClientByIdAsync_Should_Return_Null_If_Not_Found() + { + var persistentGrant = await _persistedGrantStore.GetAsync("not-existing-id"); + persistentGrant.ShouldBeNull(); + } - [Fact] - public async Task FindClientByIdAsync_Should_Return_Null_If_Not_Found() + [Fact] + public async Task FindPersistentGrantByIdAsync_Should_Return_The_PersistentGrant_If_Found() + { + //Act + var client = await _persistedGrantStore.GetAsync("38"); + + //Assert + client.ShouldNotBeNull(); + client.ClientId.ShouldBe("TestClientId-38"); + client.SubjectId.ShouldBe("TestSubject"); + client.Data.ShouldContain("TestData-38"); + client.Type.ShouldContain("TestType-38"); + } + + [Fact] + public async Task StoreAsync_Should_Store_PersistedGrant() + { + //Act + await _persistedGrantStore.StoreAsync(new PersistedGrant { - var persistentGrant = await _persistedGrantStore.GetAsync("not-existing-id"); - persistentGrant.ShouldBeNull(); - } + Key = "39", + ClientId = "TestClientId-39", + Type = "TestType-39", + SubjectId = "TestSubject", + Data = "TestData-39", + Expiration = new DateTime(2018, 1, 6, 21, 22, 23), + CreationTime = new DateTime(2018, 1, 5, 19, 20, 21) + }); + + //Assert + var persistedGrant = await _persistedGrantStore.GetAsync("39"); + persistedGrant.Key.ShouldBe("39"); + persistedGrant.ClientId.ShouldBe("TestClientId-39"); + persistedGrant.Type.ShouldBe("TestType-39"); + persistedGrant.SubjectId.ShouldBe("TestSubject"); + persistedGrant.Data.ShouldBe("TestData-39"); + + persistedGrant.Expiration.HasValue.ShouldBe(true); + persistedGrant.Expiration.Value.Year.ShouldBe(2018); + persistedGrant.Expiration.Value.Month.ShouldBe(1); + persistedGrant.Expiration.Value.Day.ShouldBe(6); + persistedGrant.Expiration.Value.Hour.ShouldBe(21); + persistedGrant.Expiration.Value.Minute.ShouldBe(22); + persistedGrant.Expiration.Value.Second.ShouldBe(23); + + persistedGrant.CreationTime.Year.ShouldBe(2018); + persistedGrant.CreationTime.Month.ShouldBe(1); + persistedGrant.CreationTime.Day.ShouldBe(5); + persistedGrant.CreationTime.Hour.ShouldBe(19); + persistedGrant.CreationTime.Minute.ShouldBe(20); + persistedGrant.CreationTime.Second.ShouldBe(21); + } + - [Fact] - public async Task FindPersistentGrantByIdAsync_Should_Return_The_PersistentGrant_If_Found() + [Fact] + public async Task StoreAsync_Should_Store_PersistedGrant_When_Exists() + { + //Act + await _persistedGrantStore.StoreAsync(new PersistedGrant { - //Act - var client = await _persistedGrantStore.GetAsync("38"); - - //Assert - client.ShouldNotBeNull(); - client.ClientId.ShouldBe("TestClientId-38"); - client.SubjectId.ShouldBe("TestSubject"); - client.Data.ShouldContain("TestData-38"); - client.Type.ShouldContain("TestType-38"); - } - - [Fact] - public async Task StoreAsync_Should_Store_PersistedGrant() + Key = "PersistedGrantKey1", + ClientId = "TestClientId-PersistedGrantKey1", + Type = "TestType-PersistedGrantKey1", + SubjectId = "TestSubject", + Data = "TestData-PersistedGrantKey1", + Expiration = new DateTime(2018, 1, 6, 21, 22, 23), + CreationTime = new DateTime(2018, 1, 5, 19, 20, 21) + }); + + //Assert + var persistedGrant = await _persistedGrantStore.GetAsync("PersistedGrantKey1"); + persistedGrant.Key.ShouldBe("PersistedGrantKey1"); + persistedGrant.ClientId.ShouldBe("TestClientId-PersistedGrantKey1"); + persistedGrant.Type.ShouldBe("TestType-PersistedGrantKey1"); + persistedGrant.SubjectId.ShouldBe("TestSubject"); + persistedGrant.Data.ShouldBe("TestData-PersistedGrantKey1"); + + persistedGrant.Expiration.HasValue.ShouldBe(true); + persistedGrant.Expiration.Value.Year.ShouldBe(2018); + persistedGrant.Expiration.Value.Month.ShouldBe(1); + persistedGrant.Expiration.Value.Day.ShouldBe(6); + persistedGrant.Expiration.Value.Hour.ShouldBe(21); + persistedGrant.Expiration.Value.Minute.ShouldBe(22); + persistedGrant.Expiration.Value.Second.ShouldBe(23); + + persistedGrant.CreationTime.Year.ShouldBe(2018); + persistedGrant.CreationTime.Month.ShouldBe(1); + persistedGrant.CreationTime.Day.ShouldBe(5); + persistedGrant.CreationTime.Hour.ShouldBe(19); + persistedGrant.CreationTime.Minute.ShouldBe(20); + persistedGrant.CreationTime.Second.ShouldBe(21); + } + + [Fact] + public async Task GetAllAsync_Should_Get_All_PersistedGrants_For_A_Given_SubjectId() + { + //Act + var persistentGrants = await _persistedGrantStore.GetAllAsync(new PersistedGrantFilter() { - //Act - await _persistedGrantStore.StoreAsync(new PersistedGrant - { - Key = "39", - ClientId = "TestClientId-39", - Type = "TestType-39", - SubjectId = "TestSubject", - Data = "TestData-39", - Expiration = new DateTime(2018, 1, 6, 21, 22, 23), - CreationTime = new DateTime(2018, 1, 5, 19, 20, 21) - }); - - //Assert - var persistedGrant = await _persistedGrantStore.GetAsync("39"); - persistedGrant.Key.ShouldBe("39"); - persistedGrant.ClientId.ShouldBe("TestClientId-39"); - persistedGrant.Type.ShouldBe("TestType-39"); - persistedGrant.SubjectId.ShouldBe("TestSubject"); - persistedGrant.Data.ShouldBe("TestData-39"); - - persistedGrant.Expiration.HasValue.ShouldBe(true); - persistedGrant.Expiration.Value.Year.ShouldBe(2018); - persistedGrant.Expiration.Value.Month.ShouldBe(1); - persistedGrant.Expiration.Value.Day.ShouldBe(6); - persistedGrant.Expiration.Value.Hour.ShouldBe(21); - persistedGrant.Expiration.Value.Minute.ShouldBe(22); - persistedGrant.Expiration.Value.Second.ShouldBe(23); - - persistedGrant.CreationTime.Year.ShouldBe(2018); - persistedGrant.CreationTime.Month.ShouldBe(1); - persistedGrant.CreationTime.Day.ShouldBe(5); - persistedGrant.CreationTime.Hour.ShouldBe(19); - persistedGrant.CreationTime.Minute.ShouldBe(20); - persistedGrant.CreationTime.Second.ShouldBe(21); - } - - - [Fact] - public async Task StoreAsync_Should_Store_PersistedGrant_When_Exists() + SubjectId = "TestSubject" + }); + + //Assert + var persistedGrants = persistentGrants as PersistedGrant[] ?? persistentGrants.ToArray(); + persistedGrants.ShouldNotBe(null); + persistedGrants.Length.ShouldBe(2); + persistedGrants[0].SubjectId.ShouldBe("TestSubject"); + persistedGrants[1].SubjectId.ShouldBe("TestSubject"); + } + + [Fact] + public async Task RemoveAsync_Should_Remove_PeristedGrant() + { + //Arrange + await _persistedGrantStore.StoreAsync(new PersistedGrant { - //Act - await _persistedGrantStore.StoreAsync(new PersistedGrant - { - Key = "PersistedGrantKey1", - ClientId = "TestClientId-PersistedGrantKey1", - Type = "TestType-PersistedGrantKey1", - SubjectId = "TestSubject", - Data = "TestData-PersistedGrantKey1", - Expiration = new DateTime(2018, 1, 6, 21, 22, 23), - CreationTime = new DateTime(2018, 1, 5, 19, 20, 21) - }); - - //Assert - var persistedGrant = await _persistedGrantStore.GetAsync("PersistedGrantKey1"); - persistedGrant.Key.ShouldBe("PersistedGrantKey1"); - persistedGrant.ClientId.ShouldBe("TestClientId-PersistedGrantKey1"); - persistedGrant.Type.ShouldBe("TestType-PersistedGrantKey1"); - persistedGrant.SubjectId.ShouldBe("TestSubject"); - persistedGrant.Data.ShouldBe("TestData-PersistedGrantKey1"); - - persistedGrant.Expiration.HasValue.ShouldBe(true); - persistedGrant.Expiration.Value.Year.ShouldBe(2018); - persistedGrant.Expiration.Value.Month.ShouldBe(1); - persistedGrant.Expiration.Value.Day.ShouldBe(6); - persistedGrant.Expiration.Value.Hour.ShouldBe(21); - persistedGrant.Expiration.Value.Minute.ShouldBe(22); - persistedGrant.Expiration.Value.Second.ShouldBe(23); - - persistedGrant.CreationTime.Year.ShouldBe(2018); - persistedGrant.CreationTime.Month.ShouldBe(1); - persistedGrant.CreationTime.Day.ShouldBe(5); - persistedGrant.CreationTime.Hour.ShouldBe(19); - persistedGrant.CreationTime.Minute.ShouldBe(20); - persistedGrant.CreationTime.Second.ShouldBe(21); - } - - [Fact] - public async Task GetAllAsync_Should_Get_All_PersistedGrants_For_A_Given_SubjectId() + Key = "#1P3R", + Type = "Type", + ClientId = "ClientId", + Data = "" + }); + + //Act + await _persistedGrantStore.RemoveAsync("#1P3R"); + + //Assert + var persistedGrant = await _persistedGrantStore.GetAsync("#1P3R"); + persistedGrant.ShouldBe(null); + } + + [Fact] + public async Task RemoveAllAsync_Should_RemoveAll_PeristedGrants_For_A_Given_Subject_And_ClientId() + { + //Arrange + var persistedGrantsWithTestSubjectX = await _persistedGrantStore.GetAllAsync(new PersistedGrantFilter() { - //Act - var persistentGrants = await _persistedGrantStore.GetAllAsync(new PersistedGrantFilter() - { - SubjectId = "TestSubject" - }); - - //Assert - var persistedGrants = persistentGrants as PersistedGrant[] ?? persistentGrants.ToArray(); - persistedGrants.ShouldNotBe(null); - persistedGrants.Length.ShouldBe(2); - persistedGrants[0].SubjectId.ShouldBe("TestSubject"); - persistedGrants[1].SubjectId.ShouldBe("TestSubject"); - } - - [Fact] - public async Task RemoveAsync_Should_Remove_PeristedGrant() + SubjectId = "TestSubject-X" + }); + var persistedGrantsWithTestSubjectXBeforeLength = persistedGrantsWithTestSubjectX.ToArray().Length; + + //Act + await _persistedGrantStore.RemoveAllAsync(new PersistedGrantFilter() { - //Arrange - await _persistedGrantStore.StoreAsync(new PersistedGrant - { - Key = "#1P3R", - Type = "Type", - ClientId = "ClientId", - Data = "" - }); - - //Act - await _persistedGrantStore.RemoveAsync("#1P3R"); - - //Assert - var persistedGrant = await _persistedGrantStore.GetAsync("#1P3R"); - persistedGrant.ShouldBe(null); - } - - [Fact] - public async Task RemoveAllAsync_Should_RemoveAll_PeristedGrants_For_A_Given_Subject_And_ClientId() + SubjectId = "TestSubject-X", + ClientId = "TestClientId-X" + }); + + //Assert + persistedGrantsWithTestSubjectXBeforeLength.ShouldBe(2); + + var persistedGrants = (await _persistedGrantStore.GetAllAsync(new PersistedGrantFilter() { - //Arrange - var persistedGrantsWithTestSubjectX = await _persistedGrantStore.GetAllAsync(new PersistedGrantFilter() - { - SubjectId = "TestSubject-X" - }); - var persistedGrantsWithTestSubjectXBeforeLength = persistedGrantsWithTestSubjectX.ToArray().Length; - - //Act - await _persistedGrantStore.RemoveAllAsync(new PersistedGrantFilter() - { - SubjectId = "TestSubject-X", - ClientId = "TestClientId-X" - }); - - //Assert - persistedGrantsWithTestSubjectXBeforeLength.ShouldBe(2); - - var persistedGrants = (await _persistedGrantStore.GetAllAsync(new PersistedGrantFilter() - { - SubjectId = "TestClientId-37" - })).ToArray(); - - persistedGrants.ShouldNotBe(null); - persistedGrants.Length.ShouldBe(0); - } + SubjectId = "TestClientId-37" + })).ToArray(); + + persistedGrants.ShouldNotBe(null); + persistedGrants.Length.ShouldBe(0); } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/CorsPolicyService_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/CorsPolicyService_Tests.cs index 9f15cf56c1..ec441fa259 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/CorsPolicyService_Tests.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/CorsPolicyService_Tests.cs @@ -5,45 +5,44 @@ using Volo.Abp.IdentityServer.Clients; using Volo.Abp.Uow; using Xunit; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class CorsPolicyService_Tests : AbpIdentityServerDomainTestBase { - public class CorsPolicyService_Tests : AbpIdentityServerDomainTestBase + private readonly ICorsPolicyService _corsPolicyService; + private readonly IClientRepository _clientRepository; + private readonly IUnitOfWorkManager _unitOfWorkManager; + + public CorsPolicyService_Tests() { - private readonly ICorsPolicyService _corsPolicyService; - private readonly IClientRepository _clientRepository; - private readonly IUnitOfWorkManager _unitOfWorkManager; + _corsPolicyService = GetRequiredService(); + _clientRepository = GetRequiredService(); + _unitOfWorkManager = GetRequiredService(); + } - public CorsPolicyService_Tests() - { - _corsPolicyService = GetRequiredService(); - _clientRepository = GetRequiredService(); - _unitOfWorkManager = GetRequiredService(); - } + [Fact] + public async Task IsOriginAllowedAsync() + { + (await _corsPolicyService.IsOriginAllowedAsync("https://client1-origin.com")).ShouldBeTrue(); + (await _corsPolicyService.IsOriginAllowedAsync("https://unknown-origin.com")).ShouldBeFalse(); + } - [Fact] - public async Task IsOriginAllowedAsync() - { - (await _corsPolicyService.IsOriginAllowedAsync("https://client1-origin.com")).ShouldBeTrue(); - (await _corsPolicyService.IsOriginAllowedAsync("https://unknown-origin.com")).ShouldBeFalse(); - } + [Fact] + public async Task IsOriginAllowedAsync_Should_Invalidate_Cache_On_Update() + { + //It does not exists before + (await _corsPolicyService.IsOriginAllowedAsync("https://new-origin.com")).ShouldBeFalse(); - [Fact] - public async Task IsOriginAllowedAsync_Should_Invalidate_Cache_On_Update() + using (var uow = _unitOfWorkManager.Begin()) { - //It does not exists before - (await _corsPolicyService.IsOriginAllowedAsync("https://new-origin.com")).ShouldBeFalse(); + var client1 = await _clientRepository.FindByClientIdAsync("ClientId1"); + client1.AddCorsOrigin("https://new-origin.com"); + await _clientRepository.UpdateAsync(client1); - using (var uow = _unitOfWorkManager.Begin()) - { - var client1 = await _clientRepository.FindByClientIdAsync("ClientId1"); - client1.AddCorsOrigin("https://new-origin.com"); - await _clientRepository.UpdateAsync(client1); - - await uow.CompleteAsync(); - } - - //It does exists now - (await _corsPolicyService.IsOriginAllowedAsync("https://new-origin.com")).ShouldBeTrue(); + await uow.CompleteAsync(); } + + //It does exists now + (await _corsPolicyService.IsOriginAllowedAsync("https://new-origin.com")).ShouldBeTrue(); } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Devices/DeviceFlowStore_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Devices/DeviceFlowStore_Tests.cs index 7d4c630de7..eaaebd3e23 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Devices/DeviceFlowStore_Tests.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Devices/DeviceFlowStore_Tests.cs @@ -7,89 +7,88 @@ using IdentityServer4.Stores; using Shouldly; using Xunit; -namespace Volo.Abp.IdentityServer.Devices +namespace Volo.Abp.IdentityServer.Devices; + +public class DeviceFlowStore_Tests : AbpIdentityServerTestBase { - public class DeviceFlowStore_Tests : AbpIdentityServerTestBase - { - private readonly IDeviceFlowStore _deviceFlowStore; + private readonly IDeviceFlowStore _deviceFlowStore; - public DeviceFlowStore_Tests() - { - _deviceFlowStore = GetRequiredService(); - } + public DeviceFlowStore_Tests() + { + _deviceFlowStore = GetRequiredService(); + } - [Fact] - public async Task StoreDeviceAuthorizationAsync() - { - await _deviceFlowStore.StoreDeviceAuthorizationAsync( - "DeviceCode-Test1", - "UserCode-Test1", - new DeviceCode - { - ClientId = "ClientId1", - AuthorizedScopes = new string[] { "s1", "s2" }, - IsAuthorized = true, - Lifetime = 42, - RequestedScopes = new string[] { "rs1" }, - Subject = new ClaimsPrincipal( - new[] - { + [Fact] + public async Task StoreDeviceAuthorizationAsync() + { + await _deviceFlowStore.StoreDeviceAuthorizationAsync( + "DeviceCode-Test1", + "UserCode-Test1", + new DeviceCode + { + ClientId = "ClientId1", + AuthorizedScopes = new string[] { "s1", "s2" }, + IsAuthorized = true, + Lifetime = 42, + RequestedScopes = new string[] { "rs1" }, + Subject = new ClaimsPrincipal( + new[] + { new ClaimsIdentity(new[] { new Claim(JwtClaimTypes.Subject, "sid1") }) - } - ) - } - ); - - void Check(DeviceCode deviceCode) - { - deviceCode.ClientId.ShouldBe("ClientId1"); - deviceCode.AuthorizedScopes.ShouldNotBeNull(); - deviceCode.AuthorizedScopes.Count().ShouldBe(2); - deviceCode.AuthorizedScopes.ShouldContain("s1"); - deviceCode.AuthorizedScopes.ShouldContain("s2"); - deviceCode.IsAuthorized.ShouldBeTrue(); - deviceCode.Lifetime.ShouldBe(42); - deviceCode.RequestedScopes.ShouldNotBeNull(); - deviceCode.RequestedScopes.Count().ShouldBe(1); - deviceCode.RequestedScopes.ShouldContain("rs1"); - deviceCode.Subject.ShouldNotBeNull(); - deviceCode.Subject.Claims.ShouldContain(x => x.Type == JwtClaimTypes.Subject && x.Value == "sid1"); + } + ) } + ); - Check(await _deviceFlowStore.FindByUserCodeAsync("UserCode-Test1")); - Check(await _deviceFlowStore.FindByDeviceCodeAsync("DeviceCode-Test1")); + void Check(DeviceCode deviceCode) + { + deviceCode.ClientId.ShouldBe("ClientId1"); + deviceCode.AuthorizedScopes.ShouldNotBeNull(); + deviceCode.AuthorizedScopes.Count().ShouldBe(2); + deviceCode.AuthorizedScopes.ShouldContain("s1"); + deviceCode.AuthorizedScopes.ShouldContain("s2"); + deviceCode.IsAuthorized.ShouldBeTrue(); + deviceCode.Lifetime.ShouldBe(42); + deviceCode.RequestedScopes.ShouldNotBeNull(); + deviceCode.RequestedScopes.Count().ShouldBe(1); + deviceCode.RequestedScopes.ShouldContain("rs1"); + deviceCode.Subject.ShouldNotBeNull(); + deviceCode.Subject.Claims.ShouldContain(x => x.Type == JwtClaimTypes.Subject && x.Value == "sid1"); } - [Fact] - public async Task RemoveByDeviceCodeAsync() - { - (await _deviceFlowStore.FindByDeviceCodeAsync("DeviceCode1")).ShouldNotBeNull(); + Check(await _deviceFlowStore.FindByUserCodeAsync("UserCode-Test1")); + Check(await _deviceFlowStore.FindByDeviceCodeAsync("DeviceCode-Test1")); + } - await _deviceFlowStore.RemoveByDeviceCodeAsync("DeviceCode1"); + [Fact] + public async Task RemoveByDeviceCodeAsync() + { + (await _deviceFlowStore.FindByDeviceCodeAsync("DeviceCode1")).ShouldNotBeNull(); - (await _deviceFlowStore.FindByDeviceCodeAsync("DeviceCode1")).ShouldBeNull(); - } + await _deviceFlowStore.RemoveByDeviceCodeAsync("DeviceCode1"); - [Fact] - public async Task UpdateByDeviceCodeAsync() - { - var deviceCode = await _deviceFlowStore.FindByDeviceCodeAsync("DeviceCode1"); - deviceCode.ShouldNotBeNull(); - deviceCode.Lifetime.ShouldBe(42); + (await _deviceFlowStore.FindByDeviceCodeAsync("DeviceCode1")).ShouldBeNull(); + } - await _deviceFlowStore.UpdateByUserCodeAsync( - "DeviceFlowCodesUserCode1", - new DeviceCode - { - Lifetime = 43 - } - ); + [Fact] + public async Task UpdateByDeviceCodeAsync() + { + var deviceCode = await _deviceFlowStore.FindByDeviceCodeAsync("DeviceCode1"); + deviceCode.ShouldNotBeNull(); + deviceCode.Lifetime.ShouldBe(42); - deviceCode = await _deviceFlowStore.FindByDeviceCodeAsync("DeviceCode1"); - deviceCode.Lifetime.ShouldBe(43); - } + await _deviceFlowStore.UpdateByUserCodeAsync( + "DeviceFlowCodesUserCode1", + new DeviceCode + { + Lifetime = 43 + } + ); + + deviceCode = await _deviceFlowStore.FindByDeviceCodeAsync("DeviceCode1"); + deviceCode.Lifetime.ShouldBe(43); } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/ResourceStore_Cache_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/ResourceStore_Cache_Tests.cs index 30f751ebdd..dbc77425af 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/ResourceStore_Cache_Tests.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/ResourceStore_Cache_Tests.cs @@ -5,75 +5,74 @@ using Shouldly; using Volo.Abp.IdentityServer.ApiResources; using Xunit; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class ResourceStore_Cache_Tests : AbpIdentityServerDomainTestBase { - public class ResourceStore_Cache_Tests : AbpIdentityServerDomainTestBase - { - private readonly IResourceStore _resourceStore; + private readonly IResourceStore _resourceStore; - public ResourceStore_Cache_Tests() - { - _resourceStore = GetRequiredService(); - } + public ResourceStore_Cache_Tests() + { + _resourceStore = GetRequiredService(); + } - [Fact] - public async Task FindIdentityResourcesByScopeNameAsync() - { - var identityResources = (await _resourceStore.FindIdentityResourcesByScopeNameAsync(new[] {"Test-Identity-Resource-Name-1"})).ToList(); - identityResources.ShouldNotBeEmpty(); - identityResources.Count.ShouldBe(1); - identityResources.First().Name.ShouldBe("Test-Identity-Resource-Name-1"); + [Fact] + public async Task FindIdentityResourcesByScopeNameAsync() + { + var identityResources = (await _resourceStore.FindIdentityResourcesByScopeNameAsync(new[] { "Test-Identity-Resource-Name-1" })).ToList(); + identityResources.ShouldNotBeEmpty(); + identityResources.Count.ShouldBe(1); + identityResources.First().Name.ShouldBe("Test-Identity-Resource-Name-1"); - var identityResources2 = (await _resourceStore.FindIdentityResourcesByScopeNameAsync(new[] {"Test-Identity-Resource-Name-1", "NewIdentityResource1"})).ToList(); - identityResources2.ShouldNotBeEmpty(); - identityResources2.Count.ShouldBe(2); - identityResources2.ShouldContain(x => x.Name == "NewIdentityResource1"); - identityResources2.ShouldContain(x => x.Name == identityResources.First().Name); - } + var identityResources2 = (await _resourceStore.FindIdentityResourcesByScopeNameAsync(new[] { "Test-Identity-Resource-Name-1", "NewIdentityResource1" })).ToList(); + identityResources2.ShouldNotBeEmpty(); + identityResources2.Count.ShouldBe(2); + identityResources2.ShouldContain(x => x.Name == "NewIdentityResource1"); + identityResources2.ShouldContain(x => x.Name == identityResources.First().Name); + } - [Fact] - public async Task FindApiScopesByNameAsync() - { - var apiScopes1 = (await _resourceStore.FindApiScopesByNameAsync(new[] {"Test-ApiScope-Name-1"})).ToList(); - apiScopes1.ShouldNotBeEmpty(); - apiScopes1.Count.ShouldBe(1); - apiScopes1.First().Name.ShouldBe("Test-ApiScope-Name-1"); + [Fact] + public async Task FindApiScopesByNameAsync() + { + var apiScopes1 = (await _resourceStore.FindApiScopesByNameAsync(new[] { "Test-ApiScope-Name-1" })).ToList(); + apiScopes1.ShouldNotBeEmpty(); + apiScopes1.Count.ShouldBe(1); + apiScopes1.First().Name.ShouldBe("Test-ApiScope-Name-1"); - var apiScopes2 = (await _resourceStore.FindApiScopesByNameAsync(new[] {"Test-ApiScope-Name-1", "Test-ApiScope-Name-2"})).ToList(); - apiScopes2.ShouldNotBeEmpty(); - apiScopes2.Count.ShouldBe(2); - apiScopes2.ShouldContain(x => x.Name == "Test-ApiScope-Name-1"); - apiScopes2.ShouldContain(x => x.Name == apiScopes1.First().Name); - } + var apiScopes2 = (await _resourceStore.FindApiScopesByNameAsync(new[] { "Test-ApiScope-Name-1", "Test-ApiScope-Name-2" })).ToList(); + apiScopes2.ShouldNotBeEmpty(); + apiScopes2.Count.ShouldBe(2); + apiScopes2.ShouldContain(x => x.Name == "Test-ApiScope-Name-1"); + apiScopes2.ShouldContain(x => x.Name == apiScopes1.First().Name); + } - [Fact] - public async Task FindApiResourcesByScopeNameAsync() - { - var apiResources1 = (await _resourceStore.FindApiResourcesByScopeNameAsync(new[] {"Test-ApiResource-ApiScope-Name-1"})).ToList(); - apiResources1.ShouldNotBeEmpty(); - apiResources1.Count.ShouldBe(1); - apiResources1.First().Name.ShouldBe("Test-ApiResource-Name-1"); + [Fact] + public async Task FindApiResourcesByScopeNameAsync() + { + var apiResources1 = (await _resourceStore.FindApiResourcesByScopeNameAsync(new[] { "Test-ApiResource-ApiScope-Name-1" })).ToList(); + apiResources1.ShouldNotBeEmpty(); + apiResources1.Count.ShouldBe(1); + apiResources1.First().Name.ShouldBe("Test-ApiResource-Name-1"); - var apiResources2 = (await _resourceStore.FindApiResourcesByScopeNameAsync(new[] {"Test-ApiResource-ApiScope-Name-1", nameof(ApiResourceScope.Scope)})).ToList(); - apiResources2.ShouldNotBeEmpty(); - apiResources2.Count.ShouldBe(2); - apiResources2.ShouldContain(x => x.Name == "Test-ApiResource-Name-1"); - apiResources2.ShouldContain(x => x.Name == apiResources1.First().Name); - } + var apiResources2 = (await _resourceStore.FindApiResourcesByScopeNameAsync(new[] { "Test-ApiResource-ApiScope-Name-1", nameof(ApiResourceScope.Scope) })).ToList(); + apiResources2.ShouldNotBeEmpty(); + apiResources2.Count.ShouldBe(2); + apiResources2.ShouldContain(x => x.Name == "Test-ApiResource-Name-1"); + apiResources2.ShouldContain(x => x.Name == apiResources1.First().Name); + } - [Fact] - public async Task FindApiResourcesByNameAsync() - { - var apiResources1 = (await _resourceStore.FindApiResourcesByNameAsync(new[] {"Test-ApiResource-Name-1"})).ToList(); - apiResources1.ShouldNotBeEmpty(); - apiResources1.Count.ShouldBe(1); - apiResources1.First().Name.ShouldBe("Test-ApiResource-Name-1"); + [Fact] + public async Task FindApiResourcesByNameAsync() + { + var apiResources1 = (await _resourceStore.FindApiResourcesByNameAsync(new[] { "Test-ApiResource-Name-1" })).ToList(); + apiResources1.ShouldNotBeEmpty(); + apiResources1.Count.ShouldBe(1); + apiResources1.First().Name.ShouldBe("Test-ApiResource-Name-1"); - var apiResources2 = (await _resourceStore.FindApiResourcesByNameAsync(new[] {"Test-ApiResource-Name-1", "NewApiResource1"})).ToList(); - apiResources2.ShouldNotBeEmpty(); - apiResources2.Count.ShouldBe(2); - apiResources2.ShouldContain(x => x.Name == "NewApiResource1"); - apiResources2.ShouldContain(x => x.Name == apiResources1.First().Name); - } + var apiResources2 = (await _resourceStore.FindApiResourcesByNameAsync(new[] { "Test-ApiResource-Name-1", "NewApiResource1" })).ToList(); + apiResources2.ShouldNotBeEmpty(); + apiResources2.Count.ShouldBe(2); + apiResources2.ShouldContain(x => x.Name == "NewApiResource1"); + apiResources2.ShouldContain(x => x.Name == apiResources1.First().Name); } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Tokens/TokenCleanupService_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Tokens/TokenCleanupService_Tests.cs index 8de564cc23..996726eb05 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Tokens/TokenCleanupService_Tests.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.Domain.Tests/Volo/Abp/IdentityServer/Tokens/TokenCleanupService_Tests.cs @@ -4,34 +4,33 @@ using Volo.Abp.IdentityServer.Devices; using Volo.Abp.IdentityServer.Grants; using Xunit; -namespace Volo.Abp.IdentityServer.Tokens +namespace Volo.Abp.IdentityServer.Tokens; + +public class TokenCleanupService_Tests : AbpIdentityServerTestBase { - public class TokenCleanupService_Tests : AbpIdentityServerTestBase - { - private readonly IPersistentGrantRepository _persistentGrantRepository; - private readonly IDeviceFlowCodesRepository _deviceFlowCodesRepository; - private readonly TokenCleanupService _tokenCleanupService; + private readonly IPersistentGrantRepository _persistentGrantRepository; + private readonly IDeviceFlowCodesRepository _deviceFlowCodesRepository; + private readonly TokenCleanupService _tokenCleanupService; - public TokenCleanupService_Tests() - { - _persistentGrantRepository = GetRequiredService(); - _deviceFlowCodesRepository = GetRequiredService(); - _tokenCleanupService = GetRequiredService(); - } + public TokenCleanupService_Tests() + { + _persistentGrantRepository = GetRequiredService(); + _deviceFlowCodesRepository = GetRequiredService(); + _tokenCleanupService = GetRequiredService(); + } - [Fact] - public async Task Should_Clear_Expired_Tokens() - { - var persistentGrantCount = await _persistentGrantRepository.GetCountAsync(); - var deviceFlowCodesCount = await _deviceFlowCodesRepository.GetCountAsync(); + [Fact] + public async Task Should_Clear_Expired_Tokens() + { + var persistentGrantCount = await _persistentGrantRepository.GetCountAsync(); + var deviceFlowCodesCount = await _deviceFlowCodesRepository.GetCountAsync(); - await _tokenCleanupService.CleanAsync(); + await _tokenCleanupService.CleanAsync(); - (await _persistentGrantRepository.GetCountAsync()) - .ShouldBe(persistentGrantCount - 1); + (await _persistentGrantRepository.GetCountAsync()) + .ShouldBe(persistentGrantCount - 1); - (await _deviceFlowCodesRepository.GetCountAsync()) - .ShouldBe(deviceFlowCodesCount - 1); - } + (await _deviceFlowCodesRepository.GetCountAsync()) + .ShouldBe(deviceFlowCodesCount - 1); } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestBase.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestBase.cs index f66709e5d1..2a79f3ce6c 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestBase.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestBase.cs @@ -1,12 +1,11 @@ using Volo.Abp.Testing; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class AbpIdentityServerTestBase : AbpIntegratedTest { - public class AbpIdentityServerTestBase : AbpIntegratedTest + protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) { - protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) - { - options.UseAutofac(); - } + options.UseAutofac(); } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestEntityFrameworkCoreModule.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestEntityFrameworkCoreModule.cs index 0c3dd27e53..d23ea92195 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestEntityFrameworkCoreModule.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestEntityFrameworkCoreModule.cs @@ -10,43 +10,42 @@ using Volo.Abp.IdentityServer.EntityFrameworkCore; using Volo.Abp.Modularity; using Volo.Abp.Threading; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +[DependsOn( + typeof(AbpIdentityEntityFrameworkCoreModule), + typeof(AbpIdentityServerEntityFrameworkCoreModule), + typeof(AbpIdentityServerTestBaseModule), + typeof(AbpEntityFrameworkCoreSqliteModule) + )] +public class AbpIdentityServerTestEntityFrameworkCoreModule : AbpModule { - [DependsOn( - typeof(AbpIdentityEntityFrameworkCoreModule), - typeof(AbpIdentityServerEntityFrameworkCoreModule), - typeof(AbpIdentityServerTestBaseModule), - typeof(AbpEntityFrameworkCoreSqliteModule) - )] - public class AbpIdentityServerTestEntityFrameworkCoreModule : AbpModule + public override void ConfigureServices(ServiceConfigurationContext context) { - public override void ConfigureServices(ServiceConfigurationContext context) - { - var sqliteConnection = CreateDatabaseAndGetConnection(); + var sqliteConnection = CreateDatabaseAndGetConnection(); - Configure(options => + Configure(options => + { + options.Configure(abpDbContextConfigurationContext => { - options.Configure(abpDbContextConfigurationContext => - { - abpDbContextConfigurationContext.DbContextOptions.UseSqlite(sqliteConnection); - }); + abpDbContextConfigurationContext.DbContextOptions.UseSqlite(sqliteConnection); }); - } + }); + } - private static SqliteConnection CreateDatabaseAndGetConnection() - { - var connection = new SqliteConnection("Data Source=:memory:"); - connection.Open(); + private static SqliteConnection CreateDatabaseAndGetConnection() + { + var connection = new SqliteConnection("Data Source=:memory:"); + connection.Open(); - new IdentityDbContext( - new DbContextOptionsBuilder().UseSqlite(connection).Options - ).GetService().CreateTables(); + new IdentityDbContext( + new DbContextOptionsBuilder().UseSqlite(connection).Options + ).GetService().CreateTables(); - new IdentityServerDbContext( - new DbContextOptionsBuilder().UseSqlite(connection).Options - ).GetService().CreateTables(); + new IdentityServerDbContext( + new DbContextOptionsBuilder().UseSqlite(connection).Options + ).GetService().CreateTables(); - return connection; - } + return connection; } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/ApiResourceRepository_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/ApiResourceRepository_Tests.cs index 965d2c8893..57c39a0653 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/ApiResourceRepository_Tests.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/ApiResourceRepository_Tests.cs @@ -1,7 +1,6 @@  -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class ApiResourceRepository_Tests //: ApiResourceRepository_Tests { - public class ApiResourceRepository_Tests //: ApiResourceRepository_Tests - { - } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/ClientRepository_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/ClientRepository_Tests.cs index ef667aec3e..69b8ef82b0 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/ClientRepository_Tests.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/ClientRepository_Tests.cs @@ -1,7 +1,6 @@ -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class ClientRepository_Tests : ClientRepository_Tests { - public class ClientRepository_Tests : ClientRepository_Tests - { - } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/IdentityResourceRepository_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/IdentityResourceRepository_Tests.cs index f6370c10b7..07d60f7c8d 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/IdentityResourceRepository_Tests.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/IdentityResourceRepository_Tests.cs @@ -1,7 +1,6 @@ -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class IdentityResourceRepository_Tests : IdentityResourceRepository_Tests { - public class IdentityResourceRepository_Tests : IdentityResourceRepository_Tests - { - } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/PersistentGrantRepository_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/PersistentGrantRepository_Tests.cs index 79bab1d23a..9146f1da34 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/PersistentGrantRepository_Tests.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/PersistentGrantRepository_Tests.cs @@ -2,10 +2,9 @@ using System.Collections.Generic; using System.Text; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class PersistentGrantRepository_Tests : PersistentGrantRepository_Tests { - public class PersistentGrantRepository_Tests : PersistentGrantRepository_Tests - { - } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/AbpIdentityServerMongoDbTestModule.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/AbpIdentityServerMongoDbTestModule.cs index b89da5ebbe..f02c37668a 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/AbpIdentityServerMongoDbTestModule.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/AbpIdentityServerMongoDbTestModule.cs @@ -5,27 +5,25 @@ using Volo.Abp.IdentityServer.MongoDB; using Volo.Abp.Modularity; using Volo.Abp.Uow; -namespace Volo.Abp.IdentityServer -{ +namespace Volo.Abp.IdentityServer; - [DependsOn( - typeof(AbpIdentityServerTestBaseModule), - typeof(AbpIdentityServerMongoDbModule), - typeof(AbpIdentityMongoDbModule) - )] - public class AbpIdentityServerMongoDbTestModule : AbpModule +[DependsOn( + typeof(AbpIdentityServerTestBaseModule), + typeof(AbpIdentityServerMongoDbModule), + typeof(AbpIdentityMongoDbModule) +)] +public class AbpIdentityServerMongoDbTestModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) { - public override void ConfigureServices(ServiceConfigurationContext context) - { - var stringArray = MongoDbFixture.ConnectionString.Split('?'); - var connectionString = stringArray[0].EnsureEndsWith('/') + - "Db_" + - Guid.NewGuid().ToString("N") + "/?" + stringArray[1]; + var stringArray = MongoDbFixture.ConnectionString.Split('?'); + var connectionString = stringArray[0].EnsureEndsWith('/') + + "Db_" + + Guid.NewGuid().ToString("N") + "/?" + stringArray[1]; - Configure(options => - { - options.ConnectionStrings.Default = connectionString; - }); - } + Configure(options => + { + options.ConnectionStrings.Default = connectionString; + }); } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/ApiResourceRepository_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/ApiResourceRepository_Tests.cs index dfe00ab4dd..8412d8fde0 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/ApiResourceRepository_Tests.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/ApiResourceRepository_Tests.cs @@ -1,9 +1,8 @@ using Xunit; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +[Collection(MongoTestCollection.Name)] +public class ApiResourceRepository_Tests : ApiResourceRepository_Tests { - [Collection(MongoTestCollection.Name)] - public class ApiResourceRepository_Tests : ApiResourceRepository_Tests - { - } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/ClientRepository_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/ClientRepository_Tests.cs index 766448daeb..b151db1a24 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/ClientRepository_Tests.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/ClientRepository_Tests.cs @@ -1,10 +1,9 @@ using Xunit; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +[Collection(MongoTestCollection.Name)] +public class ClientRepository_Tests : ClientRepository_Tests { - [Collection(MongoTestCollection.Name)] - public class ClientRepository_Tests : ClientRepository_Tests - { - } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/IdentityResourceRepository_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/IdentityResourceRepository_Tests.cs index 36ca210b36..c810cf8d79 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/IdentityResourceRepository_Tests.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/IdentityResourceRepository_Tests.cs @@ -1,9 +1,8 @@ using Xunit; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +[Collection(MongoTestCollection.Name)] +public class IdentityResourceRepository_Tests : IdentityResourceRepository_Tests { - [Collection(MongoTestCollection.Name)] - public class IdentityResourceRepository_Tests : IdentityResourceRepository_Tests - { - } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/MongoDbFixture.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/MongoDbFixture.cs index eb088c21af..3237ae6921 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/MongoDbFixture.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/MongoDbFixture.cs @@ -1,22 +1,21 @@ using System; using Mongo2Go; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class MongoDbFixture : IDisposable { - public class MongoDbFixture : IDisposable - { - private static readonly MongoDbRunner MongoDbRunner; - public static readonly string ConnectionString; + private static readonly MongoDbRunner MongoDbRunner; + public static readonly string ConnectionString; - static MongoDbFixture() - { - MongoDbRunner = MongoDbRunner.Start(singleNodeReplSet: true, singleNodeReplSetWaitTimeout: 20); - ConnectionString = MongoDbRunner.ConnectionString; - } + static MongoDbFixture() + { + MongoDbRunner = MongoDbRunner.Start(singleNodeReplSet: true, singleNodeReplSetWaitTimeout: 20); + ConnectionString = MongoDbRunner.ConnectionString; + } - public void Dispose() - { - MongoDbRunner?.Dispose(); - } + public void Dispose() + { + MongoDbRunner?.Dispose(); } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/MongoTestCollection.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/MongoTestCollection.cs index 8ac0a73624..8b2dc0716e 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/MongoTestCollection.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/MongoTestCollection.cs @@ -1,10 +1,9 @@ using Xunit; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +[CollectionDefinition(Name)] +public class MongoTestCollection : ICollectionFixture { - [CollectionDefinition(Name)] - public class MongoTestCollection : ICollectionFixture - { - public const string Name = "MongoDB Collection"; - } -} \ No newline at end of file + public const string Name = "MongoDB Collection"; +} diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/PersistentGrantRepository_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/PersistentGrantRepository_Tests.cs index 834d18fcf9..c50d9bc2c1 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/PersistentGrantRepository_Tests.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.MongoDB.Tests/Volo/Abp/IdentityServer/PersistentGrantRepository_Tests.cs @@ -1,10 +1,9 @@ using Xunit; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +[Collection(MongoTestCollection.Name)] +public class PersistentGrantRepository_Tests : PersistentGrantRepository_Tests { - [Collection(MongoTestCollection.Name)] - public class PersistentGrantRepository_Tests : PersistentGrantRepository_Tests - { - } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestBase.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestBase.cs index ca3eebd260..fe16845e98 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestBase.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestBase.cs @@ -4,14 +4,13 @@ using System.Text; using Volo.Abp.Modularity; using Volo.Abp.Testing; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class AbpIdentityServerTestBase : AbpIntegratedTest + where TStartupModule : IAbpModule { - public class AbpIdentityServerTestBase : AbpIntegratedTest - where TStartupModule : IAbpModule + protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) { - protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) - { - options.UseAutofac(); - } + options.UseAutofac(); } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestBaseModule.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestBaseModule.cs index 94624dce0b..43bb00cbd9 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestBaseModule.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestBaseModule.cs @@ -3,45 +3,44 @@ using Volo.Abp.Autofac; using Volo.Abp.Modularity; using Volo.Abp.Threading; -namespace Volo.Abp.IdentityServer -{ - [DependsOn( - typeof(AbpAutofacModule), - typeof(AbpTestBaseModule), - typeof(AbpIdentityServerDomainModule) - )] - public class AbpIdentityServerTestBaseModule : AbpModule - { - public override void PreConfigureServices(ServiceConfigurationContext context) +namespace Volo.Abp.IdentityServer; + +[DependsOn( + typeof(AbpAutofacModule), + typeof(AbpTestBaseModule), + typeof(AbpIdentityServerDomainModule) +)] +public class AbpIdentityServerTestBaseModule : AbpModule +{ + public override void PreConfigureServices(ServiceConfigurationContext context) + { + PreConfigure(options => { - PreConfigure(options => - { - options.AddDeveloperSigningCredential = false; - }); + options.AddDeveloperSigningCredential = false; + }); - PreConfigure(identityServerBuilder => - { - identityServerBuilder.AddDeveloperSigningCredential(false, System.Guid.NewGuid().ToString()); - }); - } - public override void ConfigureServices(ServiceConfigurationContext context) - { - context.Services.AddAlwaysAllowAuthorization(); - } - - public override void OnApplicationInitialization(ApplicationInitializationContext context) - { - SeedTestData(context); - } - - private static void SeedTestData(ApplicationInitializationContext context) - { - using (var scope = context.ServiceProvider.CreateScope()) - { - AsyncHelper.RunSync(() => scope.ServiceProvider - .GetRequiredService() - .BuildAsync()); - } - } - } + PreConfigure(identityServerBuilder => + { + identityServerBuilder.AddDeveloperSigningCredential(false, System.Guid.NewGuid().ToString()); + }); + } + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services.AddAlwaysAllowAuthorization(); + } + + public override void OnApplicationInitialization(ApplicationInitializationContext context) + { + SeedTestData(context); + } + + private static void SeedTestData(ApplicationInitializationContext context) + { + using (var scope = context.ServiceProvider.CreateScope()) + { + AsyncHelper.RunSync(() => scope.ServiceProvider + .GetRequiredService() + .BuildAsync()); + } + } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestData.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestData.cs index 0392cc889d..afca6589e1 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestData.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestData.cs @@ -1,14 +1,13 @@ using System; using Volo.Abp.DependencyInjection; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class AbpIdentityServerTestData : ISingletonDependency { - public class AbpIdentityServerTestData : ISingletonDependency - { - public Guid Client1Id { get; } = Guid.NewGuid(); + public Guid Client1Id { get; } = Guid.NewGuid(); - public Guid ApiResource1Id { get; } = Guid.NewGuid(); + public Guid ApiResource1Id { get; } = Guid.NewGuid(); - public Guid IdentityResource1Id { get; } = Guid.NewGuid(); - } + public Guid IdentityResource1Id { get; } = Guid.NewGuid(); } 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 38c32af64d..64c6f09209 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 @@ -18,276 +18,275 @@ using ClientClaim = Volo.Abp.IdentityServer.Clients.ClientClaim; using IdentityResource = Volo.Abp.IdentityServer.IdentityResources.IdentityResource; using PersistedGrant = Volo.Abp.IdentityServer.Grants.PersistedGrant; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public class AbpIdentityServerTestDataBuilder : ITransientDependency { - public class AbpIdentityServerTestDataBuilder : ITransientDependency + private readonly IGuidGenerator _guidGenerator; + private readonly IApiResourceRepository _apiResourceRepository; + private readonly IApiScopeRepository _apiScopeRepository; + private readonly IClientRepository _clientRepository; + private readonly IIdentityResourceRepository _identityResourceRepository; + private readonly IIdentityClaimTypeRepository _identityClaimTypeRepository; + private readonly IPersistentGrantRepository _persistentGrantRepository; + private readonly IDeviceFlowCodesRepository _deviceFlowCodesRepository; + private readonly AbpIdentityServerTestData _testData; + private readonly IClock _clock; + + public AbpIdentityServerTestDataBuilder( + IGuidGenerator guidGenerator, + IApiResourceRepository apiResourceRepository, + IApiScopeRepository apiScopeRepository, + IClientRepository clientRepository, + IIdentityResourceRepository identityResourceRepository, + IIdentityClaimTypeRepository identityClaimTypeRepository, + AbpIdentityServerTestData testData, + IPersistentGrantRepository persistentGrantRepository, + IDeviceFlowCodesRepository deviceFlowCodesRepository, + IClock clock) { - private readonly IGuidGenerator _guidGenerator; - private readonly IApiResourceRepository _apiResourceRepository; - private readonly IApiScopeRepository _apiScopeRepository; - private readonly IClientRepository _clientRepository; - private readonly IIdentityResourceRepository _identityResourceRepository; - private readonly IIdentityClaimTypeRepository _identityClaimTypeRepository; - private readonly IPersistentGrantRepository _persistentGrantRepository; - private readonly IDeviceFlowCodesRepository _deviceFlowCodesRepository; - private readonly AbpIdentityServerTestData _testData; - private readonly IClock _clock; - - public AbpIdentityServerTestDataBuilder( - IGuidGenerator guidGenerator, - IApiResourceRepository apiResourceRepository, - IApiScopeRepository apiScopeRepository, - IClientRepository clientRepository, - IIdentityResourceRepository identityResourceRepository, - IIdentityClaimTypeRepository identityClaimTypeRepository, - AbpIdentityServerTestData testData, - IPersistentGrantRepository persistentGrantRepository, - IDeviceFlowCodesRepository deviceFlowCodesRepository, - IClock clock) - { - _testData = testData; - _guidGenerator = guidGenerator; - _apiResourceRepository = apiResourceRepository; - _apiScopeRepository = apiScopeRepository; - _clientRepository = clientRepository; - _identityResourceRepository = identityResourceRepository; - _identityClaimTypeRepository = identityClaimTypeRepository; - _persistentGrantRepository = persistentGrantRepository; - _deviceFlowCodesRepository = deviceFlowCodesRepository; - _clock = clock; - } - - public async Task BuildAsync() - { - await AddApiScopes(); - await AddApiResources(); - await AddIdentityResources(); - await AddClients(); - await AddPersistentGrants(); - await AddDeviceFlowCodes(); - await AddPersistedGrants(); - await AddClaimTypes(); - } - - private async Task AddApiScopes() - { - var apiScope = new ApiScope(_guidGenerator.Create(), "Test-ApiScope-Name-1"); - - apiScope.AddUserClaim("Test-ApiScope-Claim-Type-1"); - await _apiScopeRepository.InsertAsync(apiScope); + _testData = testData; + _guidGenerator = guidGenerator; + _apiResourceRepository = apiResourceRepository; + _apiScopeRepository = apiScopeRepository; + _clientRepository = clientRepository; + _identityResourceRepository = identityResourceRepository; + _identityClaimTypeRepository = identityClaimTypeRepository; + _persistentGrantRepository = persistentGrantRepository; + _deviceFlowCodesRepository = deviceFlowCodesRepository; + _clock = clock; + } - var apiScope2 = new ApiScope(_guidGenerator.Create(), "Test-ApiScope-Name-2"); - await _apiScopeRepository.InsertAsync(apiScope2); - } + public async Task BuildAsync() + { + await AddApiScopes(); + await AddApiResources(); + await AddIdentityResources(); + await AddClients(); + await AddPersistentGrants(); + await AddDeviceFlowCodes(); + await AddPersistedGrants(); + await AddClaimTypes(); + } - private async Task AddApiResources() - { - var apiResource = new ApiResource(_testData.ApiResource1Id, "NewApiResource1"); - apiResource.Description = nameof(apiResource.Description); - apiResource.DisplayName = nameof(apiResource.DisplayName); + private async Task AddApiScopes() + { + var apiScope = new ApiScope(_guidGenerator.Create(), "Test-ApiScope-Name-1"); - apiResource.AddScope(nameof(ApiResourceScope.Scope)); - apiResource.AddUserClaim(nameof(ApiResourceClaim.Type)); - apiResource.AddSecret(nameof(ApiResourceSecret.Value)); + apiScope.AddUserClaim("Test-ApiScope-Claim-Type-1"); + await _apiScopeRepository.InsertAsync(apiScope); - await _apiResourceRepository.InsertAsync(apiResource); - await _apiResourceRepository.InsertAsync(new ApiResource(_guidGenerator.Create(), "NewApiResource2")); - await _apiResourceRepository.InsertAsync(new ApiResource(_guidGenerator.Create(), "NewApiResource3")); + var apiScope2 = new ApiScope(_guidGenerator.Create(), "Test-ApiScope-Name-2"); + await _apiScopeRepository.InsertAsync(apiScope2); + } - var apiResource2 = new ApiResource(_guidGenerator.Create(), "Test-ApiResource-Name-1") - { - Enabled = true, - Description = "Test-ApiResource-Description-1", - DisplayName = "Test-ApiResource-DisplayName-1" - }; + private async Task AddApiResources() + { + var apiResource = new ApiResource(_testData.ApiResource1Id, "NewApiResource1"); + apiResource.Description = nameof(apiResource.Description); + apiResource.DisplayName = nameof(apiResource.DisplayName); - apiResource2.AddSecret("secret".Sha256()); - apiResource2.AddScope("Test-ApiResource-ApiScope-Name-1"); - apiResource2.AddScope("Test-ApiResource-ApiScope-DisplayName-1"); - apiResource2.AddUserClaim("Test-ApiResource-Claim-Type-1"); + apiResource.AddScope(nameof(ApiResourceScope.Scope)); + apiResource.AddUserClaim(nameof(ApiResourceClaim.Type)); + apiResource.AddSecret(nameof(ApiResourceSecret.Value)); - await _apiResourceRepository.InsertAsync(apiResource2); - } + await _apiResourceRepository.InsertAsync(apiResource); + await _apiResourceRepository.InsertAsync(new ApiResource(_guidGenerator.Create(), "NewApiResource2")); + await _apiResourceRepository.InsertAsync(new ApiResource(_guidGenerator.Create(), "NewApiResource3")); - private async Task AddIdentityResources() + var apiResource2 = new ApiResource(_guidGenerator.Create(), "Test-ApiResource-Name-1") { - var identityResource1 = new IdentityResource(_testData.IdentityResource1Id, "NewIdentityResource1") - { - Description = nameof(Client.Description), - DisplayName = nameof(IdentityResource.DisplayName) - }; + Enabled = true, + Description = "Test-ApiResource-Description-1", + DisplayName = "Test-ApiResource-DisplayName-1" + }; - identityResource1.AddUserClaim(nameof(ApiResourceClaim.Type)); + apiResource2.AddSecret("secret".Sha256()); + apiResource2.AddScope("Test-ApiResource-ApiScope-Name-1"); + apiResource2.AddScope("Test-ApiResource-ApiScope-DisplayName-1"); + apiResource2.AddUserClaim("Test-ApiResource-Claim-Type-1"); - await _identityResourceRepository.InsertAsync(identityResource1); - await _identityResourceRepository.InsertAsync(new IdentityResource(_guidGenerator.Create(), "NewIdentityResource2")); - await _identityResourceRepository.InsertAsync(new IdentityResource(_guidGenerator.Create(), "NewIdentityResource3")); + await _apiResourceRepository.InsertAsync(apiResource2); + } - var identityResource2 = new IdentityResource(_guidGenerator.Create(), "Test-Identity-Resource-Name-1") - { - Description = "Test-Identity-Resource-Description-1", - DisplayName = "Test-Identity-Resource-DisplayName-1", - Required = true, - Emphasize = true - }; + private async Task AddIdentityResources() + { + var identityResource1 = new IdentityResource(_testData.IdentityResource1Id, "NewIdentityResource1") + { + Description = nameof(Client.Description), + DisplayName = nameof(IdentityResource.DisplayName) + }; - identityResource2.AddUserClaim("Test-Identity-Resource-1-IdentityClaim-Type-1"); - await _identityResourceRepository.InsertAsync(identityResource2); - } + identityResource1.AddUserClaim(nameof(ApiResourceClaim.Type)); - private async Task AddClients() + await _identityResourceRepository.InsertAsync(identityResource1); + await _identityResourceRepository.InsertAsync(new IdentityResource(_guidGenerator.Create(), "NewIdentityResource2")); + await _identityResourceRepository.InsertAsync(new IdentityResource(_guidGenerator.Create(), "NewIdentityResource3")); + + var identityResource2 = new IdentityResource(_guidGenerator.Create(), "Test-Identity-Resource-Name-1") { - var client = new Client(_testData.Client1Id, "ClientId1") - { - Description = nameof(Client.Description), - ClientName = nameof(Client.ClientName), - ClientUri = nameof(Client.ClientUri), - LogoUri = nameof(Client.LogoUri), - ProtocolType = nameof(Client.ProtocolType), - FrontChannelLogoutUri = nameof(Client.FrontChannelLogoutUri) - }; - - client.AddCorsOrigin("https://client1-origin.com"); - client.AddCorsOrigin("https://{0}.abp.io"); - client.AddClaim(nameof(ClientClaim.Type), nameof(ClientClaim.Value)); - client.AddGrantType(nameof(ClientGrantType.GrantType)); - client.AddIdentityProviderRestriction(nameof(ClientIdPRestriction.Provider)); - client.AddPostLogoutRedirectUri(nameof(ClientPostLogoutRedirectUri.PostLogoutRedirectUri)); - client.AddProperty(nameof(ClientProperty.Key), nameof(ClientProperty.Value)); - client.AddRedirectUri(nameof(ClientRedirectUri.RedirectUri)); - client.AddScope(nameof(ClientScope.Scope)); - client.AddSecret(nameof(ClientSecret.Value)); - - await _clientRepository.InsertAsync(client); - - await _clientRepository.InsertAsync(new Client(_guidGenerator.Create(), "ClientId2")); - await _clientRepository.InsertAsync(new Client(_guidGenerator.Create(), "ClientId3")); - - - var client42 = new Client(_guidGenerator.Create(), "42") - { - ProtocolType = "TestProtocol-42" - }; + Description = "Test-Identity-Resource-Description-1", + DisplayName = "Test-Identity-Resource-DisplayName-1", + Required = true, + Emphasize = true + }; + + identityResource2.AddUserClaim("Test-Identity-Resource-1-IdentityClaim-Type-1"); + await _identityResourceRepository.InsertAsync(identityResource2); + } + + private async Task AddClients() + { + var client = new Client(_testData.Client1Id, "ClientId1") + { + Description = nameof(Client.Description), + ClientName = nameof(Client.ClientName), + ClientUri = nameof(Client.ClientUri), + LogoUri = nameof(Client.LogoUri), + ProtocolType = nameof(Client.ProtocolType), + FrontChannelLogoutUri = nameof(Client.FrontChannelLogoutUri) + }; + + client.AddCorsOrigin("https://client1-origin.com"); + client.AddCorsOrigin("https://{0}.abp.io"); + client.AddClaim(nameof(ClientClaim.Type), nameof(ClientClaim.Value)); + client.AddGrantType(nameof(ClientGrantType.GrantType)); + client.AddIdentityProviderRestriction(nameof(ClientIdPRestriction.Provider)); + client.AddPostLogoutRedirectUri(nameof(ClientPostLogoutRedirectUri.PostLogoutRedirectUri)); + client.AddProperty(nameof(ClientProperty.Key), nameof(ClientProperty.Value)); + client.AddRedirectUri(nameof(ClientRedirectUri.RedirectUri)); + client.AddScope(nameof(ClientScope.Scope)); + client.AddSecret(nameof(ClientSecret.Value)); + + await _clientRepository.InsertAsync(client); + + await _clientRepository.InsertAsync(new Client(_guidGenerator.Create(), "ClientId2")); + await _clientRepository.InsertAsync(new Client(_guidGenerator.Create(), "ClientId3")); + + + var client42 = new Client(_guidGenerator.Create(), "42") + { + ProtocolType = "TestProtocol-42" + }; - client42.AddCorsOrigin("Origin1"); - client42.AddScope("Test-ApiScope-Name-1"); - await _clientRepository.InsertAsync(client42); - } + client42.AddCorsOrigin("Origin1"); + client42.AddScope("Test-ApiScope-Name-1"); + await _clientRepository.InsertAsync(client42); + } - private async Task AddPersistentGrants() + private async Task AddPersistentGrants() + { + await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) { - await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) - { - Key = "38", - ClientId = "TestClientId-38", - Type = "TestType-38", - SubjectId = "TestSubject", - Data = "TestData-38" - }); - - await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) - { - Key = "37", - ClientId = "TestClientId-37", - Type = "TestType-37", - SubjectId = "TestSubject", - Data = "TestData-37" - }); - - await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) - { - Key = "36", - ClientId = "TestClientId-X", - Type = "TestType-36", - SubjectId = "TestSubject-X", - Data = "TestData-36" - }); - - await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) - { - Key = "35", - ClientId = "TestClientId-X", - Type = "TestType-35", - SubjectId = "TestSubject-X", - Data = "TestData-35" - }); - } - - private async Task AddPersistedGrants() + Key = "38", + ClientId = "TestClientId-38", + Type = "TestType-38", + SubjectId = "TestSubject", + Data = "TestData-38" + }); + + await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) { - await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) - { - Key = "PersistedGrantKey1", - SubjectId = "PersistedGrantSubjectId1", - SessionId = "PersistedGrantSessionId1", - ClientId = "PersistedGrantClientId1", - Type = "PersistedGrantType1", - Data = "" - }); - - await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) - { - Key = "PersistedGrantKey2", - SubjectId = "PersistedGrantSubjectId2", - ClientId = "c1", - Type = "c1type", - Data = "" - }); + Key = "37", + ClientId = "TestClientId-37", + Type = "TestType-37", + SubjectId = "TestSubject", + Data = "TestData-37" + }); + + await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) + { + Key = "36", + ClientId = "TestClientId-X", + Type = "TestType-36", + SubjectId = "TestSubject-X", + Data = "TestData-36" + }); + + await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) + { + Key = "35", + ClientId = "TestClientId-X", + Type = "TestType-35", + SubjectId = "TestSubject-X", + Data = "TestData-35" + }); + } + + private async Task AddPersistedGrants() + { + await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) + { + Key = "PersistedGrantKey1", + SubjectId = "PersistedGrantSubjectId1", + SessionId = "PersistedGrantSessionId1", + ClientId = "PersistedGrantClientId1", + Type = "PersistedGrantType1", + Data = "" + }); + + await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) + { + Key = "PersistedGrantKey2", + SubjectId = "PersistedGrantSubjectId2", + ClientId = "c1", + Type = "c1type", + Data = "" + }); + + await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) + { + Key = "PersistedGrantKey3", + SubjectId = "PersistedGrantSubjectId3", + ClientId = "c1", + Type = "c1type", + Data = "", + Expiration = _clock.Now.AddDays(1), + }); + + await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) + { + Key = "PersistedGrantKey_Expired1", + SubjectId = "PersistedGrantSubjectId_Expired1", + ClientId = "c1", + Type = "c1type", + Data = "", + Expiration = _clock.Now.AddDays(-1) + }); + } - await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) + private async Task AddDeviceFlowCodes() + { + await _deviceFlowCodesRepository.InsertAsync( + new DeviceFlowCodes(_guidGenerator.Create()) { - Key = "PersistedGrantKey3", - SubjectId = "PersistedGrantSubjectId3", ClientId = "c1", - Type = "c1type", - Data = "", + DeviceCode = "DeviceCode1", Expiration = _clock.Now.AddDays(1), - }); - - await _persistentGrantRepository.InsertAsync(new PersistedGrant(_guidGenerator.Create()) + Data = "{\"Lifetime\":\"42\"}", + UserCode = "DeviceFlowCodesUserCode1", + SubjectId = "DeviceFlowCodesSubjectId1" + } + ); + + await _deviceFlowCodesRepository.InsertAsync( + new DeviceFlowCodes(_guidGenerator.Create()) { - Key = "PersistedGrantKey_Expired1", - SubjectId = "PersistedGrantSubjectId_Expired1", ClientId = "c1", - Type = "c1type", + DeviceCode = "DeviceCode2", + Expiration = _clock.Now.AddDays(-1), Data = "", - Expiration = _clock.Now.AddDays(-1) - }); - } + UserCode = "DeviceFlowCodesUserCode2", + SubjectId = "DeviceFlowCodesSubjectId2" + } + ); - private async Task AddDeviceFlowCodes() - { - await _deviceFlowCodesRepository.InsertAsync( - new DeviceFlowCodes(_guidGenerator.Create()) - { - ClientId = "c1", - DeviceCode = "DeviceCode1", - Expiration = _clock.Now.AddDays(1), - Data = "{\"Lifetime\":\"42\"}", - UserCode = "DeviceFlowCodesUserCode1", - SubjectId = "DeviceFlowCodesSubjectId1" - } - ); - - await _deviceFlowCodesRepository.InsertAsync( - new DeviceFlowCodes(_guidGenerator.Create()) - { - ClientId = "c1", - DeviceCode = "DeviceCode2", - Expiration = _clock.Now.AddDays(-1), - Data = "", - UserCode = "DeviceFlowCodesUserCode2", - SubjectId = "DeviceFlowCodesSubjectId2" - } - ); - - } - - private async Task AddClaimTypes() - { - var ageClaim = new IdentityClaimType(Guid.NewGuid(), "Age", false, false, null, null, null, - IdentityClaimValueType.Int); - await _identityClaimTypeRepository.InsertAsync(ageClaim); - } + } + + private async Task AddClaimTypes() + { + var ageClaim = new IdentityClaimType(Guid.NewGuid(), "Age", false, false, null, null, null, + IdentityClaimValueType.Int); + await _identityClaimTypeRepository.InsertAsync(ageClaim); } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/ApiResourceRepository_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/ApiResourceRepository_Tests.cs index 08c900947a..55b4feba82 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/ApiResourceRepository_Tests.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/ApiResourceRepository_Tests.cs @@ -6,28 +6,27 @@ using Volo.Abp.IdentityServer.ApiScopes; using Volo.Abp.Modularity; using Xunit; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public abstract class ApiResourceRepository_Tests : AbpIdentityServerTestBase + where TStartupModule : IAbpModule { - public abstract class ApiResourceRepository_Tests : AbpIdentityServerTestBase - where TStartupModule : IAbpModule - { - protected IApiResourceRepository apiResourceRepository { get; } + protected IApiResourceRepository apiResourceRepository { get; } - public ApiResourceRepository_Tests() - { - apiResourceRepository = ServiceProvider.GetRequiredService(); - } + public ApiResourceRepository_Tests() + { + apiResourceRepository = ServiceProvider.GetRequiredService(); + } - [Fact] - public async Task FindByNormalizedNameAsync() - { - (await apiResourceRepository.FindByNameAsync(new []{"NewApiResource2"})).ShouldNotBeNull(); - } + [Fact] + public async Task FindByNormalizedNameAsync() + { + (await apiResourceRepository.FindByNameAsync(new[] { "NewApiResource2" })).ShouldNotBeNull(); + } - [Fact] - public async Task GetListByScopesAsync() - { - (await apiResourceRepository.GetListByScopesAsync(new[] { "NewApiResource2", "NewApiResource3" })).Count.ShouldBe(2); - } + [Fact] + public async Task GetListByScopesAsync() + { + (await apiResourceRepository.GetListByScopesAsync(new[] { "NewApiResource2", "NewApiResource3" })).Count.ShouldBe(2); } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/ClientRepository_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/ClientRepository_Tests.cs index 8705a142ab..dec025a835 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/ClientRepository_Tests.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/ClientRepository_Tests.cs @@ -6,29 +6,28 @@ using Volo.Abp.IdentityServer.Clients; using Volo.Abp.Modularity; using Xunit; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public abstract class ClientRepository_Tests : AbpIdentityServerTestBase + where TStartupModule : IAbpModule { - public abstract class ClientRepository_Tests : AbpIdentityServerTestBase - where TStartupModule : IAbpModule - { - protected IClientRepository clientRepository { get; } + protected IClientRepository clientRepository { get; } - protected ClientRepository_Tests() - { - clientRepository = ServiceProvider.GetRequiredService(); - } + protected ClientRepository_Tests() + { + clientRepository = ServiceProvider.GetRequiredService(); + } - [Fact] - public async Task FindByClientIdAsync() - { - (await clientRepository.FindByClientIdAsync("ClientId2")).ShouldNotBeNull(); - } + [Fact] + public async Task FindByClientIdAsync() + { + (await clientRepository.FindByClientIdAsync("ClientId2")).ShouldNotBeNull(); + } - [Fact] - public async Task GetAllDistinctAllowedCorsOriginsAsync() - { - var origins = await clientRepository.GetAllDistinctAllowedCorsOriginsAsync(); - origins.Any().ShouldBeTrue(); - } + [Fact] + public async Task GetAllDistinctAllowedCorsOriginsAsync() + { + var origins = await clientRepository.GetAllDistinctAllowedCorsOriginsAsync(); + origins.Any().ShouldBeTrue(); } } diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/IdentityResourceRepository_Tests.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/IdentityResourceRepository_Tests.cs index 5d41b0afd2..c93377550b 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/IdentityResourceRepository_Tests.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/IdentityResourceRepository_Tests.cs @@ -8,22 +8,21 @@ using Volo.Abp.IdentityServer.IdentityResources; using Volo.Abp.Modularity; using Xunit; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public abstract class IdentityResourceRepository_Tests : AbpIdentityServerTestBase + where TStartupModule : IAbpModule { - public abstract class IdentityResourceRepository_Tests : AbpIdentityServerTestBase - where TStartupModule : IAbpModule - { - protected IIdentityResourceRepository identityResourceRepository; + protected IIdentityResourceRepository identityResourceRepository; - public IdentityResourceRepository_Tests() - { - identityResourceRepository = ServiceProvider.GetRequiredService(); - } + public IdentityResourceRepository_Tests() + { + identityResourceRepository = ServiceProvider.GetRequiredService(); + } - [Fact] - public async Task GetListByScopesAsync() - { - (await identityResourceRepository.GetListByScopeNameAsync(new[] { "", "NewIdentityResource2" })).Count.ShouldBe(1); - } + [Fact] + public async Task GetListByScopesAsync() + { + (await identityResourceRepository.GetListByScopeNameAsync(new[] { "", "NewIdentityResource2" })).Count.ShouldBe(1); } } 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 73e2537207..571eb29c63 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 @@ -7,56 +7,55 @@ using Volo.Abp.IdentityServer.Grants; using Volo.Abp.Modularity; using Xunit; -namespace Volo.Abp.IdentityServer +namespace Volo.Abp.IdentityServer; + +public abstract class PersistentGrantRepository_Tests : AbpIdentityServerTestBase + where TStartupModule : IAbpModule { - public abstract class PersistentGrantRepository_Tests : AbpIdentityServerTestBase - where TStartupModule : IAbpModule + private readonly IPersistentGrantRepository _persistentGrantRepository; + + protected PersistentGrantRepository_Tests() + { + _persistentGrantRepository = GetRequiredService(); + } + + [Fact] + public async Task FindByKeyAsync() { - private readonly IPersistentGrantRepository _persistentGrantRepository; - - protected PersistentGrantRepository_Tests() - { - _persistentGrantRepository = GetRequiredService(); - } - - [Fact] - public async Task FindByKeyAsync() - { - (await _persistentGrantRepository.FindByKeyAsync("PersistedGrantKey1")).ShouldNotBeNull(); - } - - [Fact] - public async Task GetListBySubjectIdAsync() - { - var persistedGrants = await _persistentGrantRepository.GetListBySubjectIdAsync("PersistedGrantSubjectId1"); - persistedGrants.ShouldNotBeEmpty(); - persistedGrants.ShouldContain(x => x.Key == "PersistedGrantKey1"); - } - - [Fact] - public async Task DeleteBySubjectIdAndClientId() - { - await _persistentGrantRepository.DeleteAsync("PersistedGrantSubjectId1", "PersistedGrantSessionId1", "PersistedGrantClientId1"); - - var persistedGrants = await _persistentGrantRepository.GetListAsync(); - persistedGrants.ShouldNotBeEmpty(); - persistedGrants.ShouldNotContain(x => - x.Key == "PersistedGrantKey1" && x.SubjectId == "PersistedGrantSubjectId1" && - x.ClientId == "PersistedGrantClientId1"); - } - - [Fact] - public async Task DeleteBySubjectIdAndClientIdAndType() - { - await _persistentGrantRepository.DeleteAsync("PersistedGrantSubjectId1", "PersistedGrantSessionId1", "PersistedGrantClientId1", - "PersistedGrantClientId1"); - - var persistedGrants = await _persistentGrantRepository.GetListAsync(); - persistedGrants.ShouldNotBeEmpty(); - persistedGrants.ShouldNotContain(x => - x.Key == "PersistedGrantKey1" && x.SubjectId == "PersistedGrantSubjectId1" && - x.ClientId == "PersistedGrantClientId1" && x.Type == "PersistedGrantClientId1"); - - } + (await _persistentGrantRepository.FindByKeyAsync("PersistedGrantKey1")).ShouldNotBeNull(); + } + + [Fact] + public async Task GetListBySubjectIdAsync() + { + var persistedGrants = await _persistentGrantRepository.GetListBySubjectIdAsync("PersistedGrantSubjectId1"); + persistedGrants.ShouldNotBeEmpty(); + persistedGrants.ShouldContain(x => x.Key == "PersistedGrantKey1"); + } + + [Fact] + public async Task DeleteBySubjectIdAndClientId() + { + await _persistentGrantRepository.DeleteAsync("PersistedGrantSubjectId1", "PersistedGrantSessionId1", "PersistedGrantClientId1"); + + var persistedGrants = await _persistentGrantRepository.GetListAsync(); + persistedGrants.ShouldNotBeEmpty(); + persistedGrants.ShouldNotContain(x => + x.Key == "PersistedGrantKey1" && x.SubjectId == "PersistedGrantSubjectId1" && + x.ClientId == "PersistedGrantClientId1"); + } + + [Fact] + public async Task DeleteBySubjectIdAndClientIdAndType() + { + await _persistentGrantRepository.DeleteAsync("PersistedGrantSubjectId1", "PersistedGrantSessionId1", "PersistedGrantClientId1", + "PersistedGrantClientId1"); + + var persistedGrants = await _persistentGrantRepository.GetListAsync(); + persistedGrants.ShouldNotBeEmpty(); + persistedGrants.ShouldNotContain(x => + x.Key == "PersistedGrantKey1" && x.SubjectId == "PersistedGrantSubjectId1" && + x.ClientId == "PersistedGrantClientId1" && x.Type == "PersistedGrantClientId1"); + } }