Browse Source

use file-scoped namespacing for identityServer module

pull/10696/head
Ahmet Çotur 5 years ago
parent
commit
1fb014bb8f
  1. 43
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/AbpIdentityServerDomainSharedModule.cs
  2. 15
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiResourceConsts.cs
  3. 21
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiResourceEto.cs
  4. 11
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiResourcePropertyConsts.cs
  5. 9
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiResourceScopeConsts.cs
  6. 31
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiResources/ApiResourceSecretConsts.cs
  7. 13
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiScopes/ApiScopeConsts.cs
  8. 11
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/ApiScopes/ApiScopePropertyConsts.cs
  9. 11
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientClaimConsts.cs
  10. 31
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientConsts.cs
  11. 9
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientCorsOriginConsts.cs
  12. 87
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientEto.cs
  13. 9
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientGrantTypeConsts.cs
  14. 17
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientIdPRestrictionConsts.cs
  15. 19
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUriConsts.cs
  16. 27
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientPropertyConsts.cs
  17. 19
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientRedirectUriConsts.cs
  18. 17
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientScopeConsts.cs
  19. 31
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Clients/ClientSecretConsts.cs
  20. 21
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Devices/DeviceFlowCodesConsts.cs
  21. 27
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Devices/DeviceFlowCodesEto.cs
  22. 85
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Grants/PersistedGrantConsts.cs
  23. 27
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Grants/PersistedGrantEto.cs
  24. 31
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceConsts.cs
  25. 27
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceEto.cs
  26. 11
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/IdentityResources/IdentityResourcePropertyConsts.cs
  27. 21
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/IdentityServerSecurityLogActionConsts.cs
  28. 9
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/IdentityServerSecurityLogIdentityConsts.cs
  29. 9
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/Localization/AbpIdentityServerResource.cs
  30. 17
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/IdentityServer/UserClaimConsts.cs
  31. 67
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/ObjectExtending/IdentityServerModuleExtensionConfiguration.cs
  32. 23
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/ObjectExtending/IdentityServerModuleExtensionConfigurationDictionaryExtensions.cs
  33. 21
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain.Shared/Volo/Abp/ObjectExtending/IdentityServerModuleExtensionConsts.cs
  34. 61
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpClaimsService.cs
  35. 15
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpClaimsServiceOptions.cs
  36. 25
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpClientConfigurationValidator.cs
  37. 89
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpCorsPolicyService.cs
  38. 161
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerBuilderExtensions.cs
  39. 47
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerBuilderOptions.cs
  40. 13
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerDbProperties.cs
  41. 197
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerDomainModule.cs
  42. 27
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerServiceCollectionExtensions.cs
  43. 55
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpStrictRedirectUriValidator.cs
  44. 51
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpWildcardSubdomainCorsPolicyService.cs
  45. 13
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AllowedCorsOriginsCacheItem.cs
  46. 39
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AllowedCorsOriginsCacheItemInvalidator.cs
  47. 41
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AllowedSigningAlgorithmsConverter.cs
  48. 211
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResource.cs
  49. 39
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceClaim.cs
  50. 47
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceProperty.cs
  51. 47
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceScope.cs
  52. 57
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiResourceSecret.cs
  53. 71
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/IApiResourceRepository.cs
  54. 153
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiScopes/ApiScope.cs
  55. 39
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiScopes/ApiScopeClaim.cs
  56. 47
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiScopes/ApiScopeProperty.cs
  57. 61
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiScopes/IApiScopeRepository.cs
  58. 57
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpProfileService.cs
  59. 363
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs
  60. 113
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpUserClaimsFactory.cs
  61. 47
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/SignInResultExtensions.cs
  62. 487
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/Client.cs
  63. 47
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientClaim.cs
  64. 45
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientCorsOrigin.cs
  65. 45
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientGrantType.cs
  66. 45
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientIdPRestriction.cs
  67. 47
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientPostLogoutRedirectUri.cs
  68. 47
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientProperty.cs
  69. 45
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientRedirectUri.cs
  70. 43
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientScope.cs
  71. 59
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientSecret.cs
  72. 69
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/ClientStore.cs
  73. 53
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Clients/IClientRepository.cs
  74. 35
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Devices/DeviceFlowCodes.cs
  75. 203
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Devices/DeviceFlowStore.cs
  76. 33
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Devices/IDeviceFlowCodesRepository.cs
  77. 57
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/IPersistentGrantRepository.cs
  78. 39
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrant.cs
  79. 91
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Grants/PersistedGrantStore.cs
  80. 11
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceDataSeeder.cs
  81. 61
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IIdentityResourceRepository.cs
  82. 177
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResource.cs
  83. 39
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceClaim.cs
  84. 99
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceDataSeeder.cs
  85. 47
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceProperty.cs
  86. 281
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityServerAutoMapperProfile.cs
  87. 23
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityServerBuilderExtensions.cs
  88. 95
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityServerCacheItemInvalidator.cs
  89. 31
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Jwt/JwtTokenMiddleware.cs
  90. 295
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ResourceStore.cs
  91. 45
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Secret.cs
  92. 38
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Temp/IdentityServerConfig.cs
  93. 43
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Tokens/TokenCleanupBackgroundWorker.cs
  94. 55
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Tokens/TokenCleanupOptions.cs
  95. 115
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/Tokens/TokenCleanupService.cs
  96. 25
      modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/UserClaim.cs
  97. 93
      modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/AbpIdentityServerEfCoreQueryableExtensions.cs
  98. 181
      modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResources/ApiResourceRepository.cs
  99. 135
      modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiScopes/ApiScopeRepository.cs
  100. 171
      modules/identityserver/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/Clients/ClientRepository.cs

43
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<AbpVirtualFileSystemOptions>(options =>
{
Configure<AbpVirtualFileSystemOptions>(options =>
{
options.FileSets.AddEmbedded<AbpIdentityServerDomainSharedModule>();
});
options.FileSets.AddEmbedded<AbpIdentityServerDomainSharedModule>();
});
Configure<AbpLocalizationOptions>(options =>
{
options.Resources.Add<AbpIdentityServerResource>("en")
.AddBaseTypes(
typeof(AbpValidationResource)
).AddVirtualJson("/Volo/Abp/IdentityServer/Localization/Resources");
});
Configure<AbpLocalizationOptions>(options =>
{
options.Resources.Add<AbpIdentityServerResource>("en")
.AddBaseTypes(
typeof(AbpValidationResource)
).AddVirtualJson("/Volo/Abp/IdentityServer/Localization/Resources");
});
Configure<AbpExceptionLocalizationOptions>(options =>
{
options.MapCodeNamespace("Volo.IdentityServer", typeof(AbpIdentityServerResource));
});
}
Configure<AbpExceptionLocalizationOptions>(options =>
{
options.MapCodeNamespace("Volo.IdentityServer", typeof(AbpIdentityServerResource));
});
}
}

15
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;
}

21
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; }
}

11
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;
}

9
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;
}

31
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
{
/// <summary>
/// Default value: 250
/// </summary>
public static int TypeMaxLength { get; set; } = 250;
/// <summary>
/// Default value: 250
/// </summary>
public static int TypeMaxLength { get; set; } = 250;
/// <summary>
/// Default value: 4000
/// </summary>
public static int ValueMaxLength { get; set; } = 4000;
/// <summary>
/// Default value: 4000
/// </summary>
public static int ValueMaxLength { get; set; } = 4000;
/// <summary>
/// Default value: 1000
/// </summary>
public static int DescriptionMaxLength { get; set; } = 1000;
}
/// <summary>
/// Default value: 1000
/// </summary>
public static int DescriptionMaxLength { get; set; } = 1000;
}

13
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;
}

11
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;
}

11
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;
}

31
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;
}

9
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;
}

87
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; }
}
}
public int DeviceCodeLifetime { get; set; }
}

9
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;
}

17
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
{
/// <summary>
/// Default value: 200
/// </summary>
public static int ProviderMaxLength { get; set; } = 200;
}
}
/// <summary>
/// Default value: 200
/// </summary>
public static int ProviderMaxLength { get; set; } = 200;
}

19
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
{
/// <summary>
/// Default value: 200
/// </summary>
public static int PostLogoutRedirectUriMaxLength { get; set; } = 2000;
public static int PostLogoutRedirectUriMaxLengthValue { get; set; } = 2000;
}
}
/// <summary>
/// Default value: 200
/// </summary>
public static int PostLogoutRedirectUriMaxLength { get; set; } = 2000;
public static int PostLogoutRedirectUriMaxLengthValue { get; set; } = 2000;
}

27
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
{
/// <summary>
/// Default value: 250
/// </summary>
public static int KeyMaxLength { get; set; } = 250;
/// <summary>
/// Default value: 2000
/// </summary>
public static int ValueMaxLength { get; set; } = 2000;
}
}
/// <summary>
/// Default value: 250
/// </summary>
public static int KeyMaxLength { get; set; } = 250;
/// <summary>
/// Default value: 2000
/// </summary>
public static int ValueMaxLength { get; set; } = 2000;
}

19
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
{
/// <summary>
/// Default value: 2000
/// </summary>
public static int RedirectUriMaxLength { get; set; } = 2000;
public static int RedirectUriMaxLengthValue { get; set; } = 2000;
}
}
/// <summary>
/// Default value: 2000
/// </summary>
public static int RedirectUriMaxLength { get; set; } = 2000;
public static int RedirectUriMaxLengthValue { get; set; } = 2000;
}

17
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
{
/// <summary>
/// Default value: 200
/// </summary>
public static int ScopeMaxLength { get; set; } = 200;
}
}
/// <summary>
/// Default value: 200
/// </summary>
public static int ScopeMaxLength { get; set; } = 200;
}

31
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
{
/// <summary>
/// Default value: 250
/// </summary>
public static int TypeMaxLength { get; set; } = 250;
/// <summary>
/// Default value: 250
/// </summary>
public static int TypeMaxLength { get; set; } = 250;
/// <summary>
/// Default value: 4000
/// </summary>
public static int ValueMaxLength { get; set; } = 4000;
/// <summary>
/// Default value: 4000
/// </summary>
public static int ValueMaxLength { get; set; } = 4000;
/// <summary>
/// Default value: 2000
/// </summary>
public static int DescriptionMaxLength { get; set; } = 2000;
}
/// <summary>
/// Default value: 2000
/// </summary>
public static int DescriptionMaxLength { get; set; } = 2000;
}

21
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;
}

27
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; }
}

85
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
{
/// <summary>
/// Default value: 200
/// </summary>
public static int KeyMaxLength { get; set; } = 200;
/// <summary>
/// Default value: 50
/// </summary>
public static int TypeMaxLength { get; set; } = 50;
/// <summary>
/// Default value: 200
/// </summary>
public static int SubjectIdMaxLength { get; set; } = 200;
/// <summary>
/// Default value: 100
/// </summary>
public static int SessionIdMaxLength { get; set; } = 100;
/// <summary>
/// Default value: 200
/// </summary>
public static int ClientIdMaxLength { get; set; } = 200;
/// <summary>
/// Default value: 200
/// </summary>
public static int DescriptionMaxLength { get; set; } = 200;
/// <summary>
/// Default value: 50000
/// </summary>
public static int DataMaxLength { get; set; } = 50000;
/// <summary>
/// Default value: 50000
/// </summary>
public static int DataMaxLengthValue { get; set; } = 50000;
}
/// <summary>
/// Default value: 200
/// </summary>
public static int KeyMaxLength { get; set; } = 200;
/// <summary>
/// Default value: 50
/// </summary>
public static int TypeMaxLength { get; set; } = 50;
/// <summary>
/// Default value: 200
/// </summary>
public static int SubjectIdMaxLength { get; set; } = 200;
/// <summary>
/// Default value: 100
/// </summary>
public static int SessionIdMaxLength { get; set; } = 100;
/// <summary>
/// Default value: 200
/// </summary>
public static int ClientIdMaxLength { get; set; } = 200;
/// <summary>
/// Default value: 200
/// </summary>
public static int DescriptionMaxLength { get; set; } = 200;
/// <summary>
/// Default value: 50000
/// </summary>
public static int DataMaxLength { get; set; } = 50000;
/// <summary>
/// Default value: 50000
/// </summary>
public static int DataMaxLengthValue { get; set; } = 50000;
}

27
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; }
}
}
public string Data { get; set; }
}

31
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
{
/// <summary>
/// Default value: 200
/// </summary>
public static int NameMaxLength { get; set; } = 200;
/// <summary>
/// Default value: 200
/// </summary>
public static int NameMaxLength { get; set; } = 200;
/// <summary>
/// Default value: 200
/// </summary>
public static int DisplayNameMaxLength { get; set; } = 200;
/// <summary>
/// Default value: 200
/// </summary>
public static int DisplayNameMaxLength { get; set; } = 200;
/// <summary>
/// Default value: 1000
/// </summary>
public static int DescriptionMaxLength { get; set; } = 1000;
}
/// <summary>
/// Default value: 1000
/// </summary>
public static int DescriptionMaxLength { get; set; } = 1000;
}

27
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; }
}
}
public bool ShowInDiscoveryDocument { get; set; }
}

11
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;
}

21
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";
}

9
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";
}

9
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
{
}
}

17
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
{
/// <summary>
/// Default value: 200
/// </summary>
public static int TypeMaxLength { get; set; } = 200;
}
}
/// <summary>
/// Default value: 200
/// </summary>
public static int TypeMaxLength { get; set; } = 200;
}

67
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<EntityExtensionConfiguration> configureAction)
{
public IdentityServerModuleExtensionConfiguration ConfigureClient(
Action<EntityExtensionConfiguration> configureAction)
{
return this.ConfigureEntity(
IdentityServerModuleExtensionConsts.EntityNames.Client,
configureAction
);
}
return this.ConfigureEntity(
IdentityServerModuleExtensionConsts.EntityNames.Client,
configureAction
);
}
public IdentityServerModuleExtensionConfiguration ConfigureApiResource(
Action<EntityExtensionConfiguration> configureAction)
{
return this.ConfigureEntity(
IdentityServerModuleExtensionConsts.EntityNames.ApiResource,
configureAction
);
}
public IdentityServerModuleExtensionConfiguration ConfigureApiResource(
Action<EntityExtensionConfiguration> configureAction)
{
return this.ConfigureEntity(
IdentityServerModuleExtensionConsts.EntityNames.ApiResource,
configureAction
);
}
public IdentityServerModuleExtensionConfiguration ConfigureApiScope(
Action<EntityExtensionConfiguration> configureAction)
{
return this.ConfigureEntity(
IdentityServerModuleExtensionConsts.EntityNames.ApiScope,
configureAction
);
}
public IdentityServerModuleExtensionConfiguration ConfigureApiScope(
Action<EntityExtensionConfiguration> configureAction)
{
return this.ConfigureEntity(
IdentityServerModuleExtensionConsts.EntityNames.ApiScope,
configureAction
);
}
public IdentityServerModuleExtensionConfiguration ConfigureIdentityResource(
Action<EntityExtensionConfiguration> configureAction)
{
return this.ConfigureEntity(
IdentityServerModuleExtensionConsts.EntityNames.IdentityResource,
configureAction
);
}
public IdentityServerModuleExtensionConfiguration ConfigureIdentityResource(
Action<EntityExtensionConfiguration> configureAction)
{
return this.ConfigureEntity(
IdentityServerModuleExtensionConsts.EntityNames.IdentityResource,
configureAction
);
}
}

23
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<IdentityServerModuleExtensionConfiguration> configureAction)
{
public static ModuleExtensionConfigurationDictionary ConfigureIdentityServer(
this ModuleExtensionConfigurationDictionary modules,
Action<IdentityServerModuleExtensionConfiguration> configureAction)
{
return modules.ConfigureModule(
IdentityServerModuleExtensionConsts.ModuleName,
configureAction
);
}
return modules.ConfigureModule(
IdentityServerModuleExtensionConsts.ModuleName,
configureAction
);
}
}
}

21
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";
}
}

61
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<DefaultClaimsService> logger,
IOptions<AbpClaimsServiceOptions> options)
: base(profile, logger)
{
Options = options.Value;
}
public AbpClaimsService(
IProfileService profile,
ILogger<DefaultClaimsService> logger,
IOptions<AbpClaimsServiceOptions> options)
: base(profile, logger)
{
Options = options.Value;
}
protected override IEnumerable<string> FilterRequestedClaimTypes(IEnumerable<string> claimTypes)
{
return base.FilterRequestedClaimTypes(claimTypes)
.Union(Options.RequestedClaims);
}
protected override IEnumerable<string> FilterRequestedClaimTypes(IEnumerable<string> claimTypes)
{
return base.FilterRequestedClaimTypes(claimTypes)
.Union(Options.RequestedClaims);
}
protected override IEnumerable<Claim> GetOptionalClaims(ClaimsPrincipal subject)
{
return base.GetOptionalClaims(subject)
.Union(GetAdditionalOptionalClaims(subject));
}
protected override IEnumerable<Claim> GetOptionalClaims(ClaimsPrincipal subject)
{
return base.GetOptionalClaims(subject)
.Union(GetAdditionalOptionalClaims(subject));
}
protected virtual IEnumerable<Claim> GetAdditionalOptionalClaims(ClaimsPrincipal subject)
protected virtual IEnumerable<Claim> 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;
}
}
}

15
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<string> RequestedClaims { get; }
public List<string> RequestedClaims { get; }
public AbpClaimsServiceOptions()
{
RequestedClaims = new List<string>();
}
public AbpClaimsServiceOptions()
{
RequestedClaims = new List<string>();
}
}

25
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);
}
}

89
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<AbpCorsPolicyService> Logger { get; set; }
protected IHybridServiceScopeFactory HybridServiceScopeFactory { get; }
protected IDistributedCache<AllowedCorsOriginsCacheItem> Cache { get; }
protected IdentityServerOptions Options { get; }
public AbpCorsPolicyService(
IDistributedCache<AllowedCorsOriginsCacheItem> cache,
IHybridServiceScopeFactory hybridServiceScopeFactory,
IOptions<IdentityServerOptions> options)
{
Cache = cache;
HybridServiceScopeFactory = hybridServiceScopeFactory;
Options = options.Value;
Logger = NullLogger<AbpCorsPolicyService>.Instance;
}
namespace Volo.Abp.IdentityServer;
public virtual async Task<bool> IsOriginAllowedAsync(string origin)
{
var cacheItem = await Cache.GetOrAddAsync(AllowedCorsOriginsCacheItem.AllOrigins, CreateCacheItemAsync,
() => new DistributedCacheEntryOptions()
{
AbsoluteExpirationRelativeToNow = Options.Caching.CorsExpiration
});
public class AbpCorsPolicyService : ICorsPolicyService
{
public ILogger<AbpCorsPolicyService> Logger { get; set; }
protected IHybridServiceScopeFactory HybridServiceScopeFactory { get; }
protected IDistributedCache<AllowedCorsOriginsCacheItem> Cache { get; }
protected IdentityServerOptions Options { get; }
var isAllowed = await IsOriginAllowedAsync(cacheItem.AllowedOrigins, origin);
public AbpCorsPolicyService(
IDistributedCache<AllowedCorsOriginsCacheItem> cache,
IHybridServiceScopeFactory hybridServiceScopeFactory,
IOptions<IdentityServerOptions> options)
{
Cache = cache;
HybridServiceScopeFactory = hybridServiceScopeFactory;
Options = options.Value;
Logger = NullLogger<AbpCorsPolicyService>.Instance;
}
if (!isAllowed)
public virtual async Task<bool> 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<AllowedCorsOriginsCacheItem> 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<IClientRepository>();
return new AllowedCorsOriginsCacheItem
{
AllowedOrigins = (await clientRepository.GetAllDistinctAllowedCorsOriginsAsync()).ToArray()
};
}
Logger.LogWarning($"Origin is not allowed: {origin}");
}
protected virtual Task<bool> IsOriginAllowedAsync(string[] allowedOrigins, string origin)
return isAllowed;
}
protected virtual async Task<AllowedCorsOriginsCacheItem> 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<IClientRepository>();
return new AllowedCorsOriginsCacheItem
{
AllowedOrigins = (await clientRepository.GetAllDistinctAllowedCorsOriginsAsync()).ToArray()
};
}
}
protected virtual Task<bool> IsOriginAllowedAsync(string[] allowedOrigins, string origin)
{
return Task.FromResult(allowedOrigins.Contains(origin, StringComparer.OrdinalIgnoreCase));
}
}

161
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<IdentityUser>();
builder.AddProfileService<AbpProfileService>();
builder.AddResourceOwnerValidator<AbpResourceOwnerPasswordValidator>();
//TODO: AspNet Identity integration lines. Can be extracted to a extension method
if (options.IntegrateToAspNetIdentity)
{
builder.AddAspNetIdentity<IdentityUser>();
builder.AddProfileService<AbpProfileService>();
builder.AddResourceOwnerValidator<AbpResourceOwnerPasswordValidator>();
builder.Services.Remove(builder.Services.LastOrDefault(x => x.ServiceType == typeof(IUserClaimsPrincipalFactory<IdentityUser>)));
builder.Services.AddTransient<IUserClaimsPrincipalFactory<IdentityUser>, AbpUserClaimsFactory<IdentityUser>>();
builder.Services.AddTransient<IObjectAccessor<IUserClaimsPrincipalFactory<IdentityUser>>, ObjectAccessor<AbpUserClaimsPrincipalFactory>>();
}
builder.Services.Remove(builder.Services.LastOrDefault(x => x.ServiceType == typeof(IUserClaimsPrincipalFactory<IdentityUser>)));
builder.Services.AddTransient<IUserClaimsPrincipalFactory<IdentityUser>, AbpUserClaimsFactory<IdentityUser>>();
builder.Services.AddTransient<IObjectAccessor<IUserClaimsPrincipalFactory<IdentityUser>>, ObjectAccessor<AbpUserClaimsPrincipalFactory>>();
}
builder.Services.Replace(ServiceDescriptor.Transient<IClaimsService, AbpClaimsService>());
builder.Services.Replace(ServiceDescriptor.Transient<IClaimsService, AbpClaimsService>());
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<string>();
var jsonParameters = json.GetValue("Parameters");
RSAParameters rsaParameters;
rsaParameters.D = Convert.FromBase64String(jsonParameters["D"].Value<string>());
rsaParameters.DP = Convert.FromBase64String(jsonParameters["DP"].Value<string>());
rsaParameters.DQ = Convert.FromBase64String(jsonParameters["DQ"].Value<string>());
rsaParameters.Exponent = Convert.FromBase64String(jsonParameters["Exponent"].Value<string>());
rsaParameters.InverseQ = Convert.FromBase64String(jsonParameters["InverseQ"].Value<string>());
rsaParameters.Modulus = Convert.FromBase64String(jsonParameters["Modulus"].Value<string>());
rsaParameters.P = Convert.FromBase64String(jsonParameters["P"].Value<string>());
rsaParameters.Q = Convert.FromBase64String(jsonParameters["Q"].Value<string>());
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<string>();
var jsonParameters = json.GetValue("Parameters");
RSAParameters rsaParameters;
rsaParameters.D = Convert.FromBase64String(jsonParameters["D"].Value<string>());
rsaParameters.DP = Convert.FromBase64String(jsonParameters["DP"].Value<string>());
rsaParameters.DQ = Convert.FromBase64String(jsonParameters["DQ"].Value<string>());
rsaParameters.Exponent = Convert.FromBase64String(jsonParameters["Exponent"].Value<string>());
rsaParameters.InverseQ = Convert.FromBase64String(jsonParameters["InverseQ"].Value<string>());
rsaParameters.Modulus = Convert.FromBase64String(jsonParameters["Modulus"].Value<string>());
rsaParameters.P = Convert.FromBase64String(jsonParameters["P"].Value<string>());
rsaParameters.Q = Convert.FromBase64String(jsonParameters["Q"].Value<string>());
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);
}
}
}

47
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
{
/// <summary>
/// Updates <see cref="JwtSecurityTokenHandler.DefaultInboundClaimTypeMap"/> to be compatible with identity server claims.
/// Default: true.
/// </summary>
public bool UpdateJwtSecurityTokenHandlerDefaultInboundClaimTypeMap { get; set; } = true;
/// <summary>
/// Updates <see cref="JwtSecurityTokenHandler.DefaultInboundClaimTypeMap"/> to be compatible with identity server claims.
/// Default: true.
/// </summary>
public bool UpdateJwtSecurityTokenHandlerDefaultInboundClaimTypeMap { get; set; } = true;
/// <summary>
/// Updates <see cref="AbpClaimTypes"/> to be compatible with identity server claims.
/// Default: true.
/// </summary>
public bool UpdateAbpClaimTypes { get; set; } = true;
/// <summary>
/// Updates <see cref="AbpClaimTypes"/> to be compatible with identity server claims.
/// Default: true.
/// </summary>
public bool UpdateAbpClaimTypes { get; set; } = true;
/// <summary>
/// Integrate to AspNet Identity.
/// Default: true.
/// </summary>
public bool IntegrateToAspNetIdentity { get; set; } = true;
/// <summary>
/// Integrate to AspNet Identity.
/// Default: true.
/// </summary>
public bool IntegrateToAspNetIdentity { get; set; } = true;
/// <summary>
/// Set false to suppress AddDeveloperSigningCredential() call on the IIdentityServerBuilder.
/// </summary>
public bool AddDeveloperSigningCredential { get; set; } = true;
}
}
/// <summary>
/// Set false to suppress AddDeveloperSigningCredential() call on the IIdentityServerBuilder.
/// </summary>
public bool AddDeveloperSigningCredential { get; set; } = true;
}

13
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";
}

197
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<AbpIdentityServerDomainModule>();
public override void ConfigureServices(ServiceConfigurationContext context)
Configure<AbpAutoMapperOptions>(options =>
{
context.Services.AddAutoMapperObjectMapper<AbpIdentityServerDomainModule>();
Configure<AbpAutoMapperOptions>(options =>
{
options.AddProfile<IdentityServerAutoMapperProfile>(validate: true);
});
options.AddProfile<IdentityServerAutoMapperProfile>(validate: true);
});
Configure<AbpDistributedEntityEventOptions>(options =>
{
options.EtoMappings.Add<ApiResource, ApiResourceEto>(typeof(AbpIdentityServerDomainModule));
options.EtoMappings.Add<Client, ClientEto>(typeof(AbpIdentityServerDomainModule));
options.EtoMappings.Add<DeviceFlowCodes, DeviceFlowCodesEto>(typeof(AbpIdentityServerDomainModule));
options.EtoMappings.Add<IdentityResource, IdentityResourceEto>(typeof(AbpIdentityServerDomainModule));
});
Configure<AbpDistributedEntityEventOptions>(options =>
{
options.EtoMappings.Add<ApiResource, ApiResourceEto>(typeof(AbpIdentityServerDomainModule));
options.EtoMappings.Add<Client, ClientEto>(typeof(AbpIdentityServerDomainModule));
options.EtoMappings.Add<DeviceFlowCodes, DeviceFlowCodesEto>(typeof(AbpIdentityServerDomainModule));
options.EtoMappings.Add<IdentityResource, IdentityResourceEto>(typeof(AbpIdentityServerDomainModule));
});
Configure<AbpClaimsServiceOptions>(options =>
{
options.RequestedClaims.AddRange(new []{
Configure<AbpClaimsServiceOptions>(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<AbpIdentityServerBuilderOptions>();
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<AbpIdentityServerBuilderOptions>();
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<IPersistedGrantService>())
{
services.TryAddSingleton<IPersistedGrantStore, InMemoryPersistedGrantStore>();
}
if (builderOptions.AddDeveloperSigningCredential)
{
identityServerBuilder = identityServerBuilder.AddDeveloperSigningCredential();
}
if (!services.IsAdded<IDeviceFlowStore>())
{
services.TryAddSingleton<IDeviceFlowStore, InMemoryDeviceFlowStore>();
}
identityServerBuilder.AddAbpIdentityServer(builderOptions);
if (!services.IsAdded<IClientStore>())
{
identityServerBuilder.AddInMemoryClients(configuration.GetSection("IdentityServer:Clients"));
}
services.ExecutePreConfiguredActions(identityServerBuilder);
if (!services.IsAdded<IResourceStore>())
{
identityServerBuilder.AddInMemoryApiResources(configuration.GetSection("IdentityServer:ApiResources"));
identityServerBuilder.AddInMemoryIdentityResources(configuration.GetSection("IdentityServer:IdentityResources"));
}
if (!services.IsAdded<IPersistedGrantService>())
{
services.TryAddSingleton<IPersistedGrantStore, InMemoryPersistedGrantStore>();
}
public override void PostConfigureServices(ServiceConfigurationContext context)
if (!services.IsAdded<IDeviceFlowStore>())
{
OneTimeRunner.Run(() =>
{
ModuleExtensionConfigurationHelper.ApplyEntityConfigurationToEntity(
IdentityServerModuleExtensionConsts.ModuleName,
IdentityServerModuleExtensionConsts.EntityNames.Client,
typeof(Client)
);
services.TryAddSingleton<IDeviceFlowStore, InMemoryDeviceFlowStore>();
}
ModuleExtensionConfigurationHelper.ApplyEntityConfigurationToEntity(
IdentityServerModuleExtensionConsts.ModuleName,
IdentityServerModuleExtensionConsts.EntityNames.IdentityResource,
typeof(IdentityResource)
);
if (!services.IsAdded<IClientStore>())
{
identityServerBuilder.AddInMemoryClients(configuration.GetSection("IdentityServer:Clients"));
}
ModuleExtensionConfigurationHelper.ApplyEntityConfigurationToEntity(
IdentityServerModuleExtensionConsts.ModuleName,
IdentityServerModuleExtensionConsts.EntityNames.ApiResource,
typeof(ApiResource)
);
});
if (!services.IsAdded<IResourceStore>())
{
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<IOptions<TokenCleanupOptions>>().Value;
if (options.IsCleanupEnabled)
{
var options = context.ServiceProvider.GetRequiredService<IOptions<TokenCleanupOptions>>().Value;
if (options.IsCleanupEnabled)
{
context.ServiceProvider
.GetRequiredService<IBackgroundWorkerManager>()
.Add(
context.ServiceProvider
.GetRequiredService<TokenCleanupBackgroundWorker>()
);
}
context.ServiceProvider
.GetRequiredService<IBackgroundWorkerManager>()
.Add(
context.ServiceProvider
.GetRequiredService<TokenCleanupBackgroundWorker>()
);
}
}
}

27
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<IRedirectUriValidator, AbpStrictRedirectUriValidator>());
}
services.Replace(ServiceDescriptor.Transient<IRedirectUriValidator, AbpStrictRedirectUriValidator>());
}
public static void AddAbpClientConfigurationValidator(this IServiceCollection services)
{
services.Replace(ServiceDescriptor.Transient<IClientConfigurationValidator, AbpClientConfigurationValidator>());
}
public static void AddAbpClientConfigurationValidator(this IServiceCollection services)
{
services.Replace(ServiceDescriptor.Transient<IClientConfigurationValidator, AbpClientConfigurationValidator>());
}
public static void AddAbpWildcardSubdomainCorsPolicyService(this IServiceCollection services)
{
services.Replace(ServiceDescriptor.Transient<ICorsPolicyService, AbpWildcardSubdomainCorsPolicyService>());
}
public static void AddAbpWildcardSubdomainCorsPolicyService(this IServiceCollection services)
{
services.Replace(ServiceDescriptor.Transient<ICorsPolicyService, AbpWildcardSubdomainCorsPolicyService>());
}
}

55
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<bool> IsRedirectUriValidAsync(string requestedUri, Client client)
{
public override async Task<bool> 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<bool> IsPostLogoutRedirectUriValidAsync(string requestedUri, Client client)
{
var isAllowed = await base.IsPostLogoutRedirectUriValidAsync(requestedUri, client);
return isAllowed || await IsRedirectUriValidWithDomainFormatsAsync(client.PostLogoutRedirectUris, requestedUri);
}
public override async Task<bool> IsPostLogoutRedirectUriValidAsync(string requestedUri, Client client)
protected virtual Task<bool> IsRedirectUriValidWithDomainFormatsAsync(IEnumerable<string> 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<bool> IsRedirectUriValidWithDomainFormatsAsync(IEnumerable<string> 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);
}
}

51
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<AllowedCorsOriginsCacheItem> cache,
IHybridServiceScopeFactory hybridServiceScopeFactory,
IOptions<IdentityServerOptions> options)
: base(cache, hybridServiceScopeFactory, options)
{
public AbpWildcardSubdomainCorsPolicyService(
IDistributedCache<AllowedCorsOriginsCacheItem> cache,
IHybridServiceScopeFactory hybridServiceScopeFactory,
IOptions<IdentityServerOptions> options)
: base(cache, hybridServiceScopeFactory, options)
{
}
protected override async Task<bool> IsOriginAllowedAsync(string[] allowedOrigins, string origin)
{
var isAllowed = await base.IsOriginAllowedAsync(allowedOrigins, origin);
if (isAllowed)
{
return true;
}
protected override async Task<bool> 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;
}
}

13
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; }
}
}
public string[] AllowedOrigins { get; set; }
}

39
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<EntityChangedEventData<Client>>,
ILocalEventHandler<EntityChangedEventData<ClientCorsOrigin>>,
ITransientDependency
{
public class AllowedCorsOriginsCacheItemInvalidator :
ILocalEventHandler<EntityChangedEventData<Client>>,
ILocalEventHandler<EntityChangedEventData<ClientCorsOrigin>>,
ITransientDependency
protected IDistributedCache<AllowedCorsOriginsCacheItem> Cache { get; }
public AllowedCorsOriginsCacheItemInvalidator(IDistributedCache<AllowedCorsOriginsCacheItem> cache)
{
protected IDistributedCache<AllowedCorsOriginsCacheItem> Cache { get; }
Cache = cache;
}
public AllowedCorsOriginsCacheItemInvalidator(IDistributedCache<AllowedCorsOriginsCacheItem> cache)
{
Cache = cache;
}
public virtual async Task HandleEventAsync(EntityChangedEventData<Client> eventData)
{
await Cache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins);
}
public virtual async Task HandleEventAsync(EntityChangedEventData<Client> eventData)
{
await Cache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins);
}
public virtual async Task HandleEventAsync(EntityChangedEventData<ClientCorsOrigin> eventData)
{
await Cache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins);
}
public virtual async Task HandleEventAsync(EntityChangedEventData<ClientCorsOrigin> eventData)
{
await Cache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins);
}
}
}

41
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<ICollection<string>, string>,
IValueConverter<string, ICollection<string>>
{
public class AllowedSigningAlgorithmsConverter :
IValueConverter<ICollection<string>, string>,
IValueConverter<string, ICollection<string>>
{
public static AllowedSigningAlgorithmsConverter Converter = new AllowedSigningAlgorithmsConverter();
public static AllowedSigningAlgorithmsConverter Converter = new AllowedSigningAlgorithmsConverter();
public string Convert(ICollection<string> sourceMember, ResolutionContext context)
public string Convert(ICollection<string> 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<string> Convert(string sourceMember, ResolutionContext context)
public ICollection<string> Convert(string sourceMember, ResolutionContext context)
{
var list = new HashSet<string>();
if (!String.IsNullOrWhiteSpace(sourceMember))
{
var list = new HashSet<string>();
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;
}
}

211
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<Guid>
{
public class ApiResource : FullAuditedAggregateRoot<Guid>
{
[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<ApiResourceSecret> Secrets { get; protected set; }
public virtual List<ApiResourceSecret> Secrets { get; protected set; }
public virtual List<ApiResourceScope> Scopes { get; protected set; }
public virtual List<ApiResourceScope> Scopes { get; protected set; }
public virtual List<ApiResourceClaim> UserClaims { get; protected set; }
public virtual List<ApiResourceClaim> UserClaims { get; protected set; }
public virtual List<ApiResourceProperty> Properties { get; protected set; }
public virtual List<ApiResourceProperty> 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<ApiResourceSecret>();
Scopes = new List<ApiResourceScope>();
UserClaims = new List<ApiResourceClaim>();
Properties = new List<ApiResourceProperty>();
Secrets = new List<ApiResourceSecret>();
Scopes = new List<ApiResourceScope>();
UserClaims = new List<ApiResourceClaim>();
Properties = new List<ApiResourceProperty>();
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);
}
}

39
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 };
}
}

47
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 };
}
}

47
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 };
}
}

57
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 };
}
}

71
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<ApiResource, Guid>
{
public interface IApiResourceRepository : IBasicRepository<ApiResource, Guid>
{
Task<ApiResource> FindByNameAsync(
string apiResourceName,
bool includeDetails = true,
CancellationToken cancellationToken = default
);
Task<ApiResource> FindByNameAsync(
string apiResourceName,
bool includeDetails = true,
CancellationToken cancellationToken = default
);
Task<List<ApiResource>> FindByNameAsync(
string[] apiResourceNames,
bool includeDetails = true,
CancellationToken cancellationToken = default
);
Task<List<ApiResource>> FindByNameAsync(
string[] apiResourceNames,
bool includeDetails = true,
CancellationToken cancellationToken = default
);
Task<List<ApiResource>> GetListByScopesAsync(
string[] scopeNames,
bool includeDetails = false,
CancellationToken cancellationToken = default
);
Task<List<ApiResource>> GetListByScopesAsync(
string[] scopeNames,
bool includeDetails = false,
CancellationToken cancellationToken = default
);
Task<List<ApiResource>> GetListAsync(
string sorting,
int skipCount,
int maxResultCount,
string filter = null,
bool includeDetails = false,
CancellationToken cancellationToken = default
);
Task<List<ApiResource>> GetListAsync(
string sorting,
int skipCount,
int maxResultCount,
string filter = null,
bool includeDetails = false,
CancellationToken cancellationToken = default
);
Task<long> GetCountAsync(
string filter = null,
CancellationToken cancellationToken = default
);
Task<long> GetCountAsync(
string filter = null,
CancellationToken cancellationToken = default
);
Task<bool> CheckNameExistAsync(
string name,
Guid? expectedId = null,
CancellationToken cancellationToken = default
);
}
Task<bool> CheckNameExistAsync(
string name,
Guid? expectedId = null,
CancellationToken cancellationToken = default
);
}

153
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<Guid>
{
public class ApiScope : FullAuditedAggregateRoot<Guid>
{
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<ApiScopeClaim> UserClaims { get; protected set; }
public virtual List<ApiScopeClaim> UserClaims { get; protected set; }
public virtual List<ApiScopeProperty> Properties { get; protected set; }
public virtual List<ApiScopeProperty> 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<ApiScopeClaim>();
Properties = new List<ApiScopeProperty>();
}
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<ApiScopeClaim>();
Properties = new List<ApiScopeProperty>();
}
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);
}
}

39
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 };
}
}

47
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 };
}
}

61
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<ApiScope, Guid>
{
public interface IApiScopeRepository : IBasicRepository<ApiScope, Guid>
{
Task<ApiScope> FindByNameAsync(
string scopeName,
bool includeDetails = true,
CancellationToken cancellationToken = default
);
Task<ApiScope> FindByNameAsync(
string scopeName,
bool includeDetails = true,
CancellationToken cancellationToken = default
);
Task<List<ApiScope>> GetListByNameAsync(
string[] scopeNames,
bool includeDetails = false,
CancellationToken cancellationToken = default
);
Task<List<ApiScope>> GetListByNameAsync(
string[] scopeNames,
bool includeDetails = false,
CancellationToken cancellationToken = default
);
Task<List<ApiScope>> GetListAsync(
string sorting,
int skipCount,
int maxResultCount,
string filter = null,
bool includeDetails = false,
CancellationToken cancellationToken = default
);
Task<List<ApiScope>> GetListAsync(
string sorting,
int skipCount,
int maxResultCount,
string filter = null,
bool includeDetails = false,
CancellationToken cancellationToken = default
);
Task<long> GetCountAsync(
string filter = null,
CancellationToken cancellationToken = default
);
Task<long> GetCountAsync(
string filter = null,
CancellationToken cancellationToken = default
);
Task<bool> CheckNameExistAsync(
string name,
Guid? expectedId = null,
CancellationToken cancellationToken = default
);
}
Task<bool> CheckNameExistAsync(
string name,
Guid? expectedId = null,
CancellationToken cancellationToken = default
);
}

57
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<IdentityUser>
{
public class AbpProfileService : ProfileService<IdentityUser>
{
protected ICurrentTenant CurrentTenant { get; }
protected ICurrentTenant CurrentTenant { get; }
public AbpProfileService(
IdentityUserManager userManager,
IUserClaimsPrincipalFactory<IdentityUser> claimsFactory,
ICurrentTenant currentTenant)
: base(userManager, claimsFactory)
{
CurrentTenant = currentTenant;
}
public AbpProfileService(
IdentityUserManager userManager,
IUserClaimsPrincipalFactory<IdentityUser> 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<bool> IsUserActiveAsync(IdentityUser user)
{
return Task.FromResult(user.IsActive);
}
[UnitOfWork]
public override Task<bool> IsUserActiveAsync(IdentityUser user)
{
return Task.FromResult(user.IsActive);
}
}

363
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<IdentityUser> SignInManager { get; }
protected UserManager<IdentityUser> UserManager { get; }
protected IdentitySecurityLogManager IdentitySecurityLogManager { get; }
protected ILogger<ResourceOwnerPasswordValidator<IdentityUser>> Logger { get; }
protected IStringLocalizer<AbpIdentityServerResource> Localizer { get; }
protected IHybridServiceScopeFactory ServiceScopeFactory { get; }
protected AbpIdentityOptions AbpIdentityOptions { get; }
protected IOptions<IdentityOptions> IdentityOptions { get; }
public AbpResourceOwnerPasswordValidator(
UserManager<IdentityUser> userManager,
SignInManager<IdentityUser> signInManager,
IdentitySecurityLogManager identitySecurityLogManager,
ILogger<ResourceOwnerPasswordValidator<IdentityUser>> logger,
IStringLocalizer<AbpIdentityServerResource> localizer,
IOptions<AbpIdentityOptions> abpIdentityOptions,
IHybridServiceScopeFactory serviceScopeFactory,
IOptions<IdentityOptions> identityOptions)
{
protected SignInManager<IdentityUser> SignInManager { get; }
protected UserManager<IdentityUser> UserManager { get; }
protected IdentitySecurityLogManager IdentitySecurityLogManager { get; }
protected ILogger<ResourceOwnerPasswordValidator<IdentityUser>> Logger { get; }
protected IStringLocalizer<AbpIdentityServerResource> Localizer { get; }
protected IHybridServiceScopeFactory ServiceScopeFactory { get; }
protected AbpIdentityOptions AbpIdentityOptions { get; }
protected IOptions<IdentityOptions> IdentityOptions { get; }
UserManager = userManager;
SignInManager = signInManager;
IdentitySecurityLogManager = identitySecurityLogManager;
Logger = logger;
Localizer = localizer;
ServiceScopeFactory = serviceScopeFactory;
AbpIdentityOptions = abpIdentityOptions.Value;
IdentityOptions = identityOptions;
}
public AbpResourceOwnerPasswordValidator(
UserManager<IdentityUser> userManager,
SignInManager<IdentityUser> signInManager,
IdentitySecurityLogManager identitySecurityLogManager,
ILogger<ResourceOwnerPasswordValidator<IdentityUser>> logger,
IStringLocalizer<AbpIdentityServerResource> localizer,
IOptions<AbpIdentityOptions> abpIdentityOptions,
IHybridServiceScopeFactory serviceScopeFactory,
IOptions<IdentityOptions> identityOptions)
/// <summary>
/// https://github.com/IdentityServer/IdentityServer4/blob/master/src/AspNetIdentity/src/ResourceOwnerPasswordValidator.cs#L53
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
[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);
/// <summary>
/// https://github.com/IdentityServer/IdentityServer4/blob/master/src/AspNetIdentity/src/ResourceOwnerPasswordValidator.cs#L53
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
[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<string, object>()
{
{"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<Claim>();
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<string, object>()
{
{"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<Claim>();
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<string> 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<bool> IsTfaEnabledAsync(IdentityUser user)
=> UserManager.SupportsUserTwoFactor &&
await UserManager.GetTwoFactorEnabledAsync(user) &&
(await UserManager.GetValidTwoFactorProvidersAsync(user)).Count > 0;
protected virtual Task AddCustomClaimsAsync(List<Claim> 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<string> FindClientIdAsync(ResourceOwnerPasswordValidationContext context)
{
return Task.FromResult(context.Request?.Client?.ClientId);
}
protected virtual async Task<bool> IsTfaEnabledAsync(IdentityUser user)
=> UserManager.SupportsUserTwoFactor &&
await UserManager.GetTwoFactorEnabledAsync(user) &&
(await UserManager.GetValidTwoFactorProvidersAsync(user)).Count > 0;
return Task.CompletedTask;
protected virtual Task AddCustomClaimsAsync(List<Claim> customClaims, IdentityUser user, ResourceOwnerPasswordValidationContext context)
{
if (user.TenantId.HasValue)
{
customClaims.Add(
new Claim(
AbpClaimTypes.TenantId,
user.TenantId?.ToString()
)
);
}
return Task.CompletedTask;
}
}

113
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<TUser> : IUserClaimsPrincipalFactory<TUser>
where TUser : class
{
public class AbpUserClaimsFactory<TUser> : IUserClaimsPrincipalFactory<TUser>
where TUser : class
private readonly IObjectAccessor<IUserClaimsPrincipalFactory<TUser>> _inner;
private readonly UserManager<TUser> _userManager;
public AbpUserClaimsFactory(IObjectAccessor<IUserClaimsPrincipalFactory<TUser>> inner,
UserManager<TUser> userManager)
{
_inner = inner;
_userManager = userManager;
}
public async Task<ClaimsPrincipal> CreateAsync(TUser user)
{
private readonly IObjectAccessor<IUserClaimsPrincipalFactory<TUser>> _inner;
private readonly UserManager<TUser> _userManager;
var principal = await _inner.Value.CreateAsync(user);
var identity = principal.Identities.First();
public AbpUserClaimsFactory(IObjectAccessor<IUserClaimsPrincipalFactory<TUser>> inner,
UserManager<TUser> 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<ClaimsPrincipal> 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;
}
}

47
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;
}
}

487
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<Guid>
{
public class Client : FullAuditedAggregateRoot<Guid>
{
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<ClientScope> AllowedScopes { get; set; }
public virtual List<ClientScope> AllowedScopes { get; set; }
public virtual List<ClientSecret> ClientSecrets { get; set; }
public virtual List<ClientSecret> ClientSecrets { get; set; }
public virtual List<ClientGrantType> AllowedGrantTypes { get; set; }
public virtual List<ClientGrantType> AllowedGrantTypes { get; set; }
public virtual List<ClientCorsOrigin> AllowedCorsOrigins { get; set; }
public virtual List<ClientCorsOrigin> AllowedCorsOrigins { get; set; }
public virtual List<ClientRedirectUri> RedirectUris { get; set; }
public virtual List<ClientRedirectUri> RedirectUris { get; set; }
public virtual List<ClientPostLogoutRedirectUri> PostLogoutRedirectUris { get; set; }
public virtual List<ClientPostLogoutRedirectUri> PostLogoutRedirectUris { get; set; }
public virtual List<ClientIdPRestriction> IdentityProviderRestrictions { get; set; }
public virtual List<ClientIdPRestriction> IdentityProviderRestrictions { get; set; }
public virtual List<ClientClaim> Claims { get; set; }
public virtual List<ClientClaim> Claims { get; set; }
public virtual List<ClientProperty> Properties { get; set; }
public virtual List<ClientProperty> 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<ClientScope>();
ClientSecrets = new List<ClientSecret>();
AllowedGrantTypes = new List<ClientGrantType>();
AllowedCorsOrigins = new List<ClientCorsOrigin>();
RedirectUris = new List<ClientRedirectUri>();
PostLogoutRedirectUris = new List<ClientPostLogoutRedirectUri>();
IdentityProviderRestrictions = new List<ClientIdPRestriction>();
Claims = new List<ClientClaim>();
Properties = new List<ClientProperty>();
}
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<ClientScope>();
ClientSecrets = new List<ClientSecret>();
AllowedGrantTypes = new List<ClientGrantType>();
AllowedCorsOrigins = new List<ClientCorsOrigin>();
RedirectUris = new List<ClientRedirectUri>();
PostLogoutRedirectUris = new List<ClientPostLogoutRedirectUri>();
IdentityProviderRestrictions = new List<ClientIdPRestriction>();
Claims = new List<ClientClaim>();
Properties = new List<ClientProperty>();
}
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<ClientClaim> 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<ClientClaim> 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);
}
}

47
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 };
}
}

45
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 };
}
}
}

45
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 };
}
}
}

45
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 };
}
}
}

47
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 };
}
}
}

47
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 };
}
}

45
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 };
}
}
}

43
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 };
}
}
}

59
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 };
}
}
}

69
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<AbpIdentityServerDomainModule> ObjectMapper { get; }
protected IDistributedCache<IdentityServer4.Models.Client> Cache { get; }
protected IdentityServerOptions Options { get; }
protected IClientRepository ClientRepository { get; }
protected IObjectMapper<AbpIdentityServerDomainModule> ObjectMapper { get; }
protected IDistributedCache<IdentityServer4.Models.Client> Cache { get; }
protected IdentityServerOptions Options { get; }
public ClientStore(
IClientRepository clientRepository,
IObjectMapper<AbpIdentityServerDomainModule> objectMapper,
IDistributedCache<IdentityServer4.Models.Client> cache,
IOptions<IdentityServerOptions> options)
{
ClientRepository = clientRepository;
ObjectMapper = objectMapper;
Cache = cache;
Options = options.Value;
}
public ClientStore(
IClientRepository clientRepository,
IObjectMapper<AbpIdentityServerDomainModule> objectMapper,
IDistributedCache<IdentityServer4.Models.Client> cache,
IOptions<IdentityServerOptions> options)
{
ClientRepository = clientRepository;
ObjectMapper = objectMapper;
Cache = cache;
Options = options.Value;
}
public virtual async Task<IdentityServer4.Models.Client> FindClientByIdAsync(string clientId)
{
return await GetCacheItemAsync(clientId);
}
public virtual async Task<IdentityServer4.Models.Client> FindClientByIdAsync(string clientId)
{
return await GetCacheItemAsync(clientId);
}
protected virtual async Task<IdentityServer4.Models.Client> GetCacheItemAsync(string clientId)
{
return await Cache.GetOrAddAsync(clientId, async () =>
{
var client = await ClientRepository.FindByClientIdAsync(clientId);
return ObjectMapper.Map<Client, IdentityServer4.Models.Client>(client);
},
optionsFactory: () => new DistributedCacheEntryOptions()
{
AbsoluteExpirationRelativeToNow = Options.Caching.ClientStoreExpiration
},
considerUow: true);
protected virtual async Task<IdentityServer4.Models.Client> GetCacheItemAsync(string clientId)
{
return await Cache.GetOrAddAsync(clientId, async () =>
{
var client = await ClientRepository.FindByClientIdAsync(clientId);
return ObjectMapper.Map<Client, IdentityServer4.Models.Client>(client);
},
optionsFactory: () => new DistributedCacheEntryOptions()
{
AbsoluteExpirationRelativeToNow = Options.Caching.ClientStoreExpiration
},
considerUow: true);
}
}
}

53
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<Client, Guid>
{
public interface IClientRepository : IBasicRepository<Client, Guid>
{
Task<Client> FindByClientIdAsync(
[NotNull] string clientId,
bool includeDetails = true,
CancellationToken cancellationToken = default
);
Task<Client> FindByClientIdAsync(
[NotNull] string clientId,
bool includeDetails = true,
CancellationToken cancellationToken = default
);
Task<List<Client>> GetListAsync(
string sorting,
int skipCount,
int maxResultCount,
string filter = null,
bool includeDetails = false,
CancellationToken cancellationToken = default
);
Task<List<Client>> GetListAsync(
string sorting,
int skipCount,
int maxResultCount,
string filter = null,
bool includeDetails = false,
CancellationToken cancellationToken = default
);
Task<long> GetCountAsync(
string filter = null,
CancellationToken cancellationToken = default
);
Task<long> GetCountAsync(
string filter = null,
CancellationToken cancellationToken = default
);
Task<List<string>> GetAllDistinctAllowedCorsOriginsAsync(CancellationToken cancellationToken = default);
Task<List<string>> GetAllDistinctAllowedCorsOriginsAsync(CancellationToken cancellationToken = default);
Task<bool> CheckClientIdExistAsync(
string clientId,
Guid? expectedId = null,
CancellationToken cancellationToken = default
);
}
Task<bool> CheckClientIdExistAsync(
string clientId,
Guid? expectedId = null,
CancellationToken cancellationToken = default
);
}

35
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<Guid>
{
public class DeviceFlowCodes : CreationAuditedAggregateRoot<Guid>
{
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)
{
}
}
}

203
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<DeviceCode> 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<DeviceCode> FindByUserCodeAsync(string userCode)
{
Check.NotNull(userCode, nameof(userCode));
return DeserializeToDeviceCode(deviceCodes.Data);
}
var deviceCodes = await DeviceFlowCodesRepository
.FindByUserCodeAsync(userCode)
;
public virtual async Task<DeviceCode> 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<DeviceCode> 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<DeviceCode>(data);
protected virtual DeviceCode DeserializeToDeviceCode([CanBeNull] string data)
{
if (data == null)
{
return null;
}
return PersistentGrantSerializer.Deserialize<DeviceCode>(data);
}
}

33
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<DeviceFlowCodes, Guid>
{
public interface IDeviceFlowCodesRepository : IBasicRepository<DeviceFlowCodes, Guid>
{
Task<DeviceFlowCodes> FindByUserCodeAsync(
string userCode,
CancellationToken cancellationToken = default
);
Task<DeviceFlowCodes> FindByUserCodeAsync(
string userCode,
CancellationToken cancellationToken = default
);
Task<DeviceFlowCodes> FindByDeviceCodeAsync(
string deviceCode,
CancellationToken cancellationToken = default
);
Task<DeviceFlowCodes> FindByDeviceCodeAsync(
string deviceCode,
CancellationToken cancellationToken = default
);
Task<List<DeviceFlowCodes>> GetListByExpirationAsync(
DateTime maxExpirationDate,
int maxResultCount,
CancellationToken cancellationToken = default
);
}
Task<List<DeviceFlowCodes>> GetListByExpirationAsync(
DateTime maxExpirationDate,
int maxResultCount,
CancellationToken cancellationToken = default
);
}

57
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<PersistedGrant, Guid>
{
public interface IPersistentGrantRepository : IBasicRepository<PersistedGrant, Guid>
{
Task<List<PersistedGrant>> GetListAsync(
string subjectId,
string sessionId,
string clientId,
string type, bool includeDetails = false, CancellationToken cancellationToken = default);
Task<List<PersistedGrant>> GetListAsync(
string subjectId,
string sessionId,
string clientId,
string type, bool includeDetails = false, CancellationToken cancellationToken = default);
Task<PersistedGrant> FindByKeyAsync(
string key,
CancellationToken cancellationToken = default
);
Task<PersistedGrant> FindByKeyAsync(
string key,
CancellationToken cancellationToken = default
);
Task<List<PersistedGrant>> GetListBySubjectIdAsync(
string key,
CancellationToken cancellationToken = default
);
Task<List<PersistedGrant>> GetListBySubjectIdAsync(
string key,
CancellationToken cancellationToken = default
);
Task<List<PersistedGrant>> GetListByExpirationAsync(
DateTime maxExpirationDate,
int maxResultCount,
CancellationToken cancellationToken = default
);
Task<List<PersistedGrant>> 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
);
}

39
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<Guid>
{
public class PersistedGrant : AggregateRoot<Guid>
{
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)
{
}
}

91
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<AbpIdentityServerDomainModule> ObjectMapper { get; }
protected IGuidGenerator GuidGenerator { get; }
public PersistedGrantStore(IPersistentGrantRepository persistentGrantRepository,
IObjectMapper<AbpIdentityServerDomainModule> objectMapper, IGuidGenerator guidGenerator)
{
protected IPersistentGrantRepository PersistentGrantRepository { get; }
protected IObjectMapper<AbpIdentityServerDomainModule> ObjectMapper { get; }
protected IGuidGenerator GuidGenerator { get; }
PersistentGrantRepository = persistentGrantRepository;
ObjectMapper = objectMapper;
GuidGenerator = guidGenerator;
}
public PersistedGrantStore(IPersistentGrantRepository persistentGrantRepository,
IObjectMapper<AbpIdentityServerDomainModule> 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<IdentityServer4.Models.PersistedGrant, PersistedGrant>(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<IdentityServer4.Models.PersistedGrant, PersistedGrant>(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<IdentityServer4.Models.PersistedGrant> GetAsync(string key)
{
var persistedGrant = await PersistentGrantRepository.FindByKeyAsync(key);
return ObjectMapper.Map<PersistedGrant, IdentityServer4.Models.PersistedGrant>(persistedGrant);
}
public virtual async Task<IdentityServer4.Models.PersistedGrant> GetAsync(string key)
{
var persistedGrant = await PersistentGrantRepository.FindByKeyAsync(key);
return ObjectMapper.Map<PersistedGrant, IdentityServer4.Models.PersistedGrant>(persistedGrant);
}
public virtual async Task<IEnumerable<IdentityServer4.Models.PersistedGrant>> GetAllAsync(PersistedGrantFilter filter)
{
var persistedGrants = await PersistentGrantRepository.GetListAsync(filter.SubjectId, filter.SessionId, filter.ClientId, filter.Type);
return ObjectMapper.Map<List<PersistedGrant>, List<IdentityServer4.Models.PersistedGrant>>(persistedGrants);
}
public virtual async Task<IEnumerable<IdentityServer4.Models.PersistedGrant>> GetAllAsync(PersistedGrantFilter filter)
{
var persistedGrants = await PersistentGrantRepository.GetListAsync(filter.SubjectId, filter.SessionId, filter.ClientId, filter.Type);
return ObjectMapper.Map<List<PersistedGrant>, List<IdentityServer4.Models.PersistedGrant>>(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);
}
}

11
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();
}
}
Task CreateStandardResourcesAsync();
}

61
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<IdentityResource, Guid>
{
public interface IIdentityResourceRepository : IBasicRepository<IdentityResource, Guid>
{
Task<List<IdentityResource>> GetListByScopeNameAsync(
string[] scopeNames,
bool includeDetails = false,
CancellationToken cancellationToken = default
);
Task<List<IdentityResource>> GetListByScopeNameAsync(
string[] scopeNames,
bool includeDetails = false,
CancellationToken cancellationToken = default
);
Task<List<IdentityResource>> GetListAsync(
string sorting,
int skipCount,
int maxResultCount,
string filter = null,
bool includeDetails = false,
CancellationToken cancellationToken = default
);
Task<List<IdentityResource>> GetListAsync(
string sorting,
int skipCount,
int maxResultCount,
string filter = null,
bool includeDetails = false,
CancellationToken cancellationToken = default
);
Task<long> GetCountAsync(
string filter = null,
CancellationToken cancellationToken = default
);
Task<long> GetCountAsync(
string filter = null,
CancellationToken cancellationToken = default
);
Task<IdentityResource> FindByNameAsync(
string name,
bool includeDetails = true,
CancellationToken cancellationToken = default
);
Task<IdentityResource> FindByNameAsync(
string name,
bool includeDetails = true,
CancellationToken cancellationToken = default
);
Task<bool> CheckNameExistAsync(
string name,
Guid? expectedId = null,
CancellationToken cancellationToken = default
);
}
Task<bool> CheckNameExistAsync(
string name,
Guid? expectedId = null,
CancellationToken cancellationToken = default
);
}

177
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<Guid>
{
public class IdentityResource : FullAuditedAggregateRoot<Guid>
{
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<IdentityResourceClaim> UserClaims { get; set; }
public virtual List<IdentityResourceClaim> UserClaims { get; set; }
public virtual List<IdentityResourceProperty> Properties { get; set; }
public virtual List<IdentityResourceProperty> 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<IdentityResourceClaim>();
Properties = new List<IdentityResourceProperty>();
}
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<IdentityResourceClaim>();
Properties = new List<IdentityResourceProperty>();
}
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);
}
}

39
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 };
}
}

99
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
)
);
}
}

47
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 };
}
}

281
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
/// <summary>
/// TODO: Reverse maps will not used probably. Remove those will not used
/// </summary>
public IdentityServerAutoMapperProfile()
{
CreateMap<UserClaim, string>()
.ConstructUsing(src => src.Type)
.ReverseMap()
.ForMember(dest => dest.Type, opt => opt.MapFrom(src => src));
CreateClientMap();
CreateApiResourceMap();
CreateApiScopeMap();
CreateIdentityResourceMap();
CreatePersistedGrantMap();
CreateDeviceFlowCodesMap();
}
private void CreateClientMap()
{
CreateMap<ClientCorsOrigin, string>()
.ConstructUsing(src => src.Origin)
.ReverseMap()
.ForMember(dest => dest.Origin, opt => opt.MapFrom(src => src));
CreateMap<ClientProperty, KeyValuePair<string, string>>()
.ReverseMap();
CreateMap<Client, IdentityServer4.Models.Client>()
.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<ClientCorsOrigin, string>()
.ConstructUsing(src => src.Origin)
.ReverseMap()
.ForMember(dest => dest.Origin, opt => opt.MapFrom(src => src));
CreateMap<ClientIdPRestriction, string>()
.ConstructUsing(src => src.Provider)
.ReverseMap()
.ForMember(dest => dest.Provider, opt => opt.MapFrom(src => src));
CreateMap<ClientClaim, Claim>(MemberList.None)
.ConstructUsing(src => new Claim(src.Type, src.Value))
.ReverseMap();
CreateMap<ClientClaim, IdentityServer4.Models.ClientClaim>(MemberList.None)
.ConstructUsing(src => new IdentityServer4.Models.ClientClaim(src.Type, src.Value, ClaimValueTypes.String))
.ReverseMap();
CreateMap<ClientScope, string>()
.ConstructUsing(src => src.Scope)
.ReverseMap()
.ForMember(dest => dest.Scope, opt => opt.MapFrom(src => src));
CreateMap<ClientPostLogoutRedirectUri, string>()
.ConstructUsing(src => src.PostLogoutRedirectUri)
.ReverseMap()
.ForMember(dest => dest.PostLogoutRedirectUri, opt => opt.MapFrom(src => src));
CreateMap<ClientRedirectUri, string>()
.ConstructUsing(src => src.RedirectUri)
.ReverseMap()
.ForMember(dest => dest.RedirectUri, opt => opt.MapFrom(src => src));
CreateMap<ClientGrantType, string>()
.ConstructUsing(src => src.GrantType)
.ReverseMap()
.ForMember(dest => dest.GrantType, opt => opt.MapFrom(src => src));
CreateMap<ClientSecret, IdentityServer4.Models.Secret>(MemberList.Destination)
.ForMember(dest => dest.Type, opt => opt.Condition(srs => srs != null))
.ReverseMap();
CreateMap<Client, ClientEto>();
}
private void CreateApiResourceMap()
{
CreateMap<ApiResource, IdentityServer4.Models.ApiResource>()
.ForMember(dest => dest.ApiSecrets, opt => opt.MapFrom(src => src.Secrets));
CreateMap<ApiResourceSecret, IdentityServer4.Models.Secret>();
CreateMap<ApiResourceScope, string>()
.ConstructUsing(x => x.Scope)
.ReverseMap()
.ForMember(dest => dest.Scope, opt => opt.MapFrom(src => src));
CreateMap<ApiResourceProperty, KeyValuePair<string, string>>()
.ReverseMap();
CreateMap<ApiResource, ApiResourceEto>();
}
private void CreateApiScopeMap()
{
CreateMap<ApiScopeProperty, KeyValuePair<string, string>>()
.ReverseMap();
CreateMap<ApiScopeClaim, string>()
.ConstructUsing(x => x.Type)
.ReverseMap()
.ForMember(dest => dest.Type, opt => opt.MapFrom(src => src));
CreateMap<ApiScope, IdentityServer4.Models.ApiScope>(MemberList.Destination)
.ConstructUsing(src => new IdentityServer4.Models.ApiScope())
.ReverseMap();
}
private void CreateIdentityResourceMap()
{
CreateMap<IdentityResource, IdentityServer4.Models.IdentityResource>()
.ConstructUsing(src => new IdentityServer4.Models.IdentityResource());
CreateMap<IdentityResourceClaim, string>()
.ConstructUsing(x => x.Type)
.ReverseMap()
.ForMember(dest => dest.Type, opt => opt.MapFrom(src => src));
CreateMap<IdentityResourceProperty, KeyValuePair<string, string>>()
.ReverseMap();
CreateMap<IdentityResource, IdentityResourceEto>();
}
private void CreatePersistedGrantMap()
{
//TODO: Why PersistedGrant mapping is in this profile?
CreateMap<PersistedGrant, IdentityServer4.Models.PersistedGrant>().ReverseMap();
CreateMap<PersistedGrant, PersistedGrantEto>();
}
private void CreateDeviceFlowCodesMap()
{
/// <summary>
/// TODO: Reverse maps will not used probably. Remove those will not used
/// </summary>
public IdentityServerAutoMapperProfile()
{
CreateMap<UserClaim, string>()
.ConstructUsing(src => src.Type)
.ReverseMap()
.ForMember(dest => dest.Type, opt => opt.MapFrom(src => src));
CreateClientMap();
CreateApiResourceMap();
CreateApiScopeMap();
CreateIdentityResourceMap();
CreatePersistedGrantMap();
CreateDeviceFlowCodesMap();
}
private void CreateClientMap()
{
CreateMap<ClientCorsOrigin, string>()
.ConstructUsing(src => src.Origin)
.ReverseMap()
.ForMember(dest => dest.Origin, opt => opt.MapFrom(src => src));
CreateMap<ClientProperty, KeyValuePair<string, string>>()
.ReverseMap();
CreateMap<Client, IdentityServer4.Models.Client>()
.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<ClientCorsOrigin, string>()
.ConstructUsing(src => src.Origin)
.ReverseMap()
.ForMember(dest => dest.Origin, opt => opt.MapFrom(src => src));
CreateMap<ClientIdPRestriction, string>()
.ConstructUsing(src => src.Provider)
.ReverseMap()
.ForMember(dest => dest.Provider, opt => opt.MapFrom(src => src));
CreateMap<ClientClaim, Claim>(MemberList.None)
.ConstructUsing(src => new Claim(src.Type, src.Value))
.ReverseMap();
CreateMap<ClientClaim, IdentityServer4.Models.ClientClaim>(MemberList.None)
.ConstructUsing(src => new IdentityServer4.Models.ClientClaim(src.Type, src.Value, ClaimValueTypes.String))
.ReverseMap();
CreateMap<ClientScope, string>()
.ConstructUsing(src => src.Scope)
.ReverseMap()
.ForMember(dest => dest.Scope, opt => opt.MapFrom(src => src));
CreateMap<ClientPostLogoutRedirectUri, string>()
.ConstructUsing(src => src.PostLogoutRedirectUri)
.ReverseMap()
.ForMember(dest => dest.PostLogoutRedirectUri, opt => opt.MapFrom(src => src));
CreateMap<ClientRedirectUri, string>()
.ConstructUsing(src => src.RedirectUri)
.ReverseMap()
.ForMember(dest => dest.RedirectUri, opt => opt.MapFrom(src => src));
CreateMap<ClientGrantType, string>()
.ConstructUsing(src => src.GrantType)
.ReverseMap()
.ForMember(dest => dest.GrantType, opt => opt.MapFrom(src => src));
CreateMap<ClientSecret, IdentityServer4.Models.Secret>(MemberList.Destination)
.ForMember(dest => dest.Type, opt => opt.Condition(srs => srs != null))
.ReverseMap();
CreateMap<Client, ClientEto>();
}
private void CreateApiResourceMap()
{
CreateMap<ApiResource, IdentityServer4.Models.ApiResource>()
.ForMember(dest => dest.ApiSecrets, opt => opt.MapFrom(src => src.Secrets));
CreateMap<ApiResourceSecret, IdentityServer4.Models.Secret>();
CreateMap<ApiResourceScope, string>()
.ConstructUsing(x => x.Scope)
.ReverseMap()
.ForMember(dest => dest.Scope, opt => opt.MapFrom(src => src));
CreateMap<ApiResourceProperty, KeyValuePair<string, string>>()
.ReverseMap();
CreateMap<ApiResource, ApiResourceEto>();
}
private void CreateApiScopeMap()
{
CreateMap<ApiScopeProperty, KeyValuePair<string, string>>()
.ReverseMap();
CreateMap<ApiScopeClaim, string>()
.ConstructUsing(x => x.Type)
.ReverseMap()
.ForMember(dest => dest.Type, opt => opt.MapFrom(src => src));
CreateMap<ApiScope, IdentityServer4.Models.ApiScope>(MemberList.Destination)
.ConstructUsing(src => new IdentityServer4.Models.ApiScope())
.ReverseMap();
}
private void CreateIdentityResourceMap()
{
CreateMap<IdentityResource, IdentityServer4.Models.IdentityResource>()
.ConstructUsing(src => new IdentityServer4.Models.IdentityResource());
CreateMap<IdentityResourceClaim, string>()
.ConstructUsing(x => x.Type)
.ReverseMap()
.ForMember(dest => dest.Type, opt => opt.MapFrom(src => src));
CreateMap<IdentityResourceProperty, KeyValuePair<string, string>>()
.ReverseMap();
CreateMap<IdentityResource, IdentityResourceEto>();
}
private void CreatePersistedGrantMap()
{
//TODO: Why PersistedGrant mapping is in this profile?
CreateMap<PersistedGrant, IdentityServer4.Models.PersistedGrant>().ReverseMap();
CreateMap<PersistedGrant, PersistedGrantEto>();
}
private void CreateDeviceFlowCodesMap()
{
CreateMap<DeviceFlowCodes, DeviceFlowCodesEto>();
}
CreateMap<DeviceFlowCodes, DeviceFlowCodesEto>();
}
}

23
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<IPersistedGrantStore, PersistedGrantStore>();
builder.Services.AddTransient<IDeviceFlowStore, DeviceFlowStore>();
builder.Services.AddTransient<IPersistedGrantStore, PersistedGrantStore>();
builder.Services.AddTransient<IDeviceFlowStore, DeviceFlowStore>();
return builder
.AddClientStore<ClientStore>()
.AddResourceStore<ResourceStore>()
.AddCorsPolicyService<AbpCorsPolicyService>();
}
return builder
.AddClientStore<ClientStore>()
.AddResourceStore<ResourceStore>()
.AddCorsPolicyService<AbpCorsPolicyService>();
}
}
}

95
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<EntityChangedEventData<Client>>,
ILocalEventHandler<EntityChangedEventData<ClientCorsOrigin>>,
ILocalEventHandler<EntityChangedEventData<IdentityResource>>,
ILocalEventHandler<EntityChangedEventData<ApiResource>>,
ILocalEventHandler<EntityChangedEventData<ApiScope>>,
ITransientDependency
{
public class IdentityServerCacheItemInvalidator :
ILocalEventHandler<EntityChangedEventData<Client>>,
ILocalEventHandler<EntityChangedEventData<ClientCorsOrigin>>,
ILocalEventHandler<EntityChangedEventData<IdentityResource>>,
ILocalEventHandler<EntityChangedEventData<ApiResource>>,
ILocalEventHandler<EntityChangedEventData<ApiScope>>,
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<Client> eventData)
{
var clientCache = ServiceProvider.GetRequiredService<IDistributedCache<IdentityServer4.Models.Client>>();
await clientCache.RemoveAsync(eventData.Entity.ClientId, considerUow: true);
public virtual async Task HandleEventAsync(EntityChangedEventData<Client> eventData)
{
var clientCache = ServiceProvider.GetRequiredService<IDistributedCache<IdentityServer4.Models.Client>>();
await clientCache.RemoveAsync(eventData.Entity.ClientId, considerUow: true);
var corsCache = ServiceProvider.GetRequiredService<IDistributedCache<AllowedCorsOriginsCacheItem>>();
await corsCache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins);
}
var corsCache = ServiceProvider.GetRequiredService<IDistributedCache<AllowedCorsOriginsCacheItem>>();
await corsCache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins);
}
public async Task HandleEventAsync(EntityChangedEventData<ClientCorsOrigin> eventData)
{
var corsCache = ServiceProvider.GetRequiredService<IDistributedCache<AllowedCorsOriginsCacheItem>>();
await corsCache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins);
}
public async Task HandleEventAsync(EntityChangedEventData<ClientCorsOrigin> eventData)
{
var corsCache = ServiceProvider.GetRequiredService<IDistributedCache<AllowedCorsOriginsCacheItem>>();
await corsCache.RemoveAsync(AllowedCorsOriginsCacheItem.AllOrigins);
}
public virtual async Task HandleEventAsync(EntityChangedEventData<IdentityResource> eventData)
{
var cache = ServiceProvider.GetRequiredService<IDistributedCache<IdentityServer4.Models.IdentityResource>>();
await cache.RemoveAsync(eventData.Entity.Name);
public virtual async Task HandleEventAsync(EntityChangedEventData<IdentityResource> eventData)
{
var cache = ServiceProvider.GetRequiredService<IDistributedCache<IdentityServer4.Models.IdentityResource>>();
await cache.RemoveAsync(eventData.Entity.Name);
var resourcesCache = ServiceProvider.GetRequiredService<IDistributedCache<IdentityServer4.Models.Resources>>();
await resourcesCache.RemoveAsync(ResourceStore.AllResourcesKey);
}
var resourcesCache = ServiceProvider.GetRequiredService<IDistributedCache<IdentityServer4.Models.Resources>>();
await resourcesCache.RemoveAsync(ResourceStore.AllResourcesKey);
}
public virtual async Task HandleEventAsync(EntityChangedEventData<ApiResource> eventData)
{
var cache = ServiceProvider.GetRequiredService<IDistributedCache<IdentityServer4.Models.ApiResource>>();
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<ApiResource> eventData)
{
var cache = ServiceProvider.GetRequiredService<IDistributedCache<IdentityServer4.Models.ApiResource>>();
await cache.RemoveAsync(ResourceStore.ApiResourceNameCacheKeyPrefix + eventData.Entity.Name);
await cache.RemoveManyAsync(eventData.Entity.Scopes.Select(x => ResourceStore.ApiResourceScopeNameCacheKeyPrefix + x.Scope));
var resourcesCache = ServiceProvider.GetRequiredService<IDistributedCache<IdentityServer4.Models.Resources>>();
await resourcesCache.RemoveAsync(ResourceStore.AllResourcesKey);
}
var resourcesCache = ServiceProvider.GetRequiredService<IDistributedCache<IdentityServer4.Models.Resources>>();
await resourcesCache.RemoveAsync(ResourceStore.AllResourcesKey);
}
public virtual async Task HandleEventAsync(EntityChangedEventData<ApiScope> eventData)
{
var cache = ServiceProvider.GetRequiredService<IDistributedCache<IdentityServer4.Models.ApiScope>>();
await cache.RemoveAsync(eventData.Entity.Name);
public virtual async Task HandleEventAsync(EntityChangedEventData<ApiScope> eventData)
{
var cache = ServiceProvider.GetRequiredService<IDistributedCache<IdentityServer4.Models.ApiScope>>();
await cache.RemoveAsync(eventData.Entity.Name);
var resourcesCache = ServiceProvider.GetRequiredService<IDistributedCache<IdentityServer4.Models.Resources>>();
await resourcesCache.RemoveAsync(ResourceStore.AllResourcesKey);
}
var resourcesCache = ServiceProvider.GetRequiredService<IDistributedCache<IdentityServer4.Models.Resources>>();
await resourcesCache.RemoveAsync(ResourceStore.AllResourcesKey);
}
}

31
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();
});
}
}
}

295
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<AbpIdentityServerDomainModule> ObjectMapper { get; }
protected IDistributedCache<IdentityServer4.Models.IdentityResource> IdentityResourceCache { get; }
protected IDistributedCache<IdentityServer4.Models.ApiScope> ApiScopeCache { get; }
protected IDistributedCache<IdentityServer4.Models.ApiResource> ApiResourceCache { get; }
protected IDistributedCache<IdentityServer4.Models.Resources> ResourcesCache { get; }
protected IdentityServerOptions Options { get; }
public ResourceStore(
IIdentityResourceRepository identityResourceRepository,
IObjectMapper<AbpIdentityServerDomainModule> objectMapper,
IApiResourceRepository apiResourceRepository,
IApiScopeRepository apiScopeRepository,
IDistributedCache<IdentityServer4.Models.IdentityResource> identityResourceCache,
IDistributedCache<IdentityServer4.Models.ApiScope> apiScopeCache,
IDistributedCache<IdentityServer4.Models.ApiResource> apiResourceCache,
IDistributedCache<Resources> resourcesCache,
IOptions<IdentityServerOptions> 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<AbpIdentityServerDomainModule> ObjectMapper { get; }
protected IDistributedCache<IdentityServer4.Models.IdentityResource> IdentityResourceCache { get; }
protected IDistributedCache<IdentityServer4.Models.ApiScope> ApiScopeCache { get; }
protected IDistributedCache<IdentityServer4.Models.ApiResource> ApiResourceCache { get; }
protected IDistributedCache<IdentityServer4.Models.Resources> ResourcesCache { get; }
protected IdentityServerOptions Options { get; }
public ResourceStore(
IIdentityResourceRepository identityResourceRepository,
IObjectMapper<AbpIdentityServerDomainModule> objectMapper,
IApiResourceRepository apiResourceRepository,
IApiScopeRepository apiScopeRepository,
IDistributedCache<IdentityServer4.Models.IdentityResource> identityResourceCache,
IDistributedCache<IdentityServer4.Models.ApiScope> apiScopeCache,
IDistributedCache<IdentityServer4.Models.ApiResource> apiResourceCache,
IDistributedCache<Resources> resourcesCache,
IOptions<IdentityServerOptions> 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;
}
/// <summary>
/// Gets identity resources by scope name.
/// </summary>
public virtual async Task<IEnumerable<IdentityServer4.Models.IdentityResource>> FindIdentityResourcesByScopeNameAsync(IEnumerable<string> scopeNames)
{
return await GetCacheItemsAsync(
IdentityResourceCache,
scopeNames,
async keys => await IdentityResourceRepository.GetListByScopeNameAsync(keys, includeDetails: true),
(models, cacheKeyPrefix)=> new List<IEnumerable<KeyValuePair<string, IdentityServer4.Models.IdentityResource>>>
{
/// <summary>
/// Gets identity resources by scope name.
/// </summary>
public virtual async Task<IEnumerable<IdentityServer4.Models.IdentityResource>> FindIdentityResourcesByScopeNameAsync(IEnumerable<string> scopeNames)
{
return await GetCacheItemsAsync(
IdentityResourceCache,
scopeNames,
async keys => await IdentityResourceRepository.GetListByScopeNameAsync(keys, includeDetails: true),
(models, cacheKeyPrefix) => new List<IEnumerable<KeyValuePair<string, IdentityServer4.Models.IdentityResource>>>
{
models.Select(x => new KeyValuePair<string, IdentityServer4.Models.IdentityResource>(AddCachePrefix(x.Name, cacheKeyPrefix), x))
});
}
});
}
/// <summary>
/// Gets API scopes by scope name.
/// </summary>
public virtual async Task<IEnumerable<IdentityServer4.Models.ApiScope>> FindApiScopesByNameAsync(IEnumerable<string> scopeNames)
{
return await GetCacheItemsAsync(
ApiScopeCache,
scopeNames,
async keys => await ApiScopeRepository.GetListByNameAsync(keys, includeDetails: true),
(models, cacheKeyPrefix) => new List<IEnumerable<KeyValuePair<string, IdentityServer4.Models.ApiScope>>>
{
/// <summary>
/// Gets API scopes by scope name.
/// </summary>
public virtual async Task<IEnumerable<IdentityServer4.Models.ApiScope>> FindApiScopesByNameAsync(IEnumerable<string> scopeNames)
{
return await GetCacheItemsAsync(
ApiScopeCache,
scopeNames,
async keys => await ApiScopeRepository.GetListByNameAsync(keys, includeDetails: true),
(models, cacheKeyPrefix) => new List<IEnumerable<KeyValuePair<string, IdentityServer4.Models.ApiScope>>>
{
models.Select(x => new KeyValuePair<string, IdentityServer4.Models.ApiScope>(AddCachePrefix(x.Name, cacheKeyPrefix), x))
});
}
});
}
/// <summary>
/// Gets API resources by scope name.
/// </summary>
public virtual async Task<IEnumerable<IdentityServer4.Models.ApiResource>> FindApiResourcesByScopeNameAsync(IEnumerable<string> scopeNames)
/// <summary>
/// Gets API resources by scope name.
/// </summary>
public virtual async Task<IEnumerable<IdentityServer4.Models.ApiResource>> FindApiResourcesByScopeNameAsync(IEnumerable<string> scopeNames)
{
return await GetCacheItemsAsync<ApiResource, IdentityServer4.Models.ApiResource>(
ApiResourceCache,
scopeNames,
async keys => await ApiResourceRepository.GetListByScopesAsync(keys, includeDetails: true),
(models, cacheKeyPrefix) =>
{
return models
.Select(model => model.Scopes.Select(scope => new KeyValuePair<string, IdentityServer4.Models.ApiResource>(AddCachePrefix(scope, cacheKeyPrefix), model)).ToList())
.Where(scopes => scopes.Any()).Cast<IEnumerable<KeyValuePair<string, IdentityServer4.Models.ApiResource>>>().ToList();
}, ApiResourceScopeNameCacheKeyPrefix);
}
/// <summary>
/// Gets API resources by API resource name.
/// </summary>
public virtual async Task<IEnumerable<IdentityServer4.Models.ApiResource>> FindApiResourcesByNameAsync(IEnumerable<string> apiResourceNames)
{
return await GetCacheItemsAsync(
ApiResourceCache,
apiResourceNames,
async keys => await ApiResourceRepository.FindByNameAsync(keys, includeDetails: true),
(models, cacheKeyPrefix) => new List<IEnumerable<KeyValuePair<string, IdentityServer4.Models.ApiResource>>>
{
models.Select(x => new KeyValuePair<string, IdentityServer4.Models.ApiResource>(AddCachePrefix(x.Name, cacheKeyPrefix), x))
}, ApiResourceNameCacheKeyPrefix);
}
/// <summary>
/// Gets all resources.
/// </summary>
public virtual async Task<IdentityServer4.Models.Resources> GetAllResourcesAsync()
{
return await ResourcesCache.GetOrAddAsync(AllResourcesKey, async () =>
{
return await GetCacheItemsAsync<ApiResource, IdentityServer4.Models.ApiResource>(
ApiResourceCache,
scopeNames,
async keys => await ApiResourceRepository.GetListByScopesAsync(keys, includeDetails: true),
(models, cacheKeyPrefix) =>
{
return models
.Select(model => model.Scopes.Select(scope => new KeyValuePair<string, IdentityServer4.Models.ApiResource>(AddCachePrefix(scope, cacheKeyPrefix), model)).ToList())
.Where(scopes => scopes.Any()).Cast<IEnumerable<KeyValuePair<string, IdentityServer4.Models.ApiResource>>>().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<Volo.Abp.IdentityServer.IdentityResources.IdentityResource>, List<IdentityServer4.Models.IdentityResource>>(identityResources),
ObjectMapper.Map<List<Volo.Abp.IdentityServer.ApiResources.ApiResource>, List<IdentityServer4.Models.ApiResource>>(apiResources),
ObjectMapper.Map<List<Volo.Abp.IdentityServer.ApiScopes.ApiScope>, List<IdentityServer4.Models.ApiScope>>(apiScopes));
}, () => new DistributedCacheEntryOptions
{
AbsoluteExpirationRelativeToNow = Options.Caching.ClientStoreExpiration
});
}
/// <summary>
/// Gets API resources by API resource name.
/// </summary>
public virtual async Task<IEnumerable<IdentityServer4.Models.ApiResource>> FindApiResourcesByNameAsync(IEnumerable<string> apiResourceNames)
protected virtual async Task<IEnumerable<TModel>> GetCacheItemsAsync<TEntity, TModel>(
IDistributedCache<TModel> cache,
IEnumerable<string> keys,
Func<string[], Task<List<TEntity>>> entityFactory,
Func<List<TModel>, string, List<IEnumerable<KeyValuePair<string, TModel>>>> 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<IEnumerable<KeyValuePair<string, IdentityServer4.Models.ApiResource>>>
{
models.Select(x => new KeyValuePair<string, IdentityServer4.Models.ApiResource>(AddCachePrefix(x.Name, cacheKeyPrefix), x))
}, ApiResourceNameCacheKeyPrefix);
return cacheItems.Select(x => x.Value);
}
/// <summary>
/// Gets all resources.
/// </summary>
public virtual async Task<IdentityServer4.Models.Resources> GetAllResourcesAsync()
var otherKeys = RemoveCachePrefix(cacheItems.Where(x => x.Value == null).Select(x => x.Key), cacheKeyPrefix).ToArray();
var otherModels = ObjectMapper.Map<List<TEntity>, List<TModel>>(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<Volo.Abp.IdentityServer.IdentityResources.IdentityResource>, List<IdentityServer4.Models.IdentityResource>>(identityResources),
ObjectMapper.Map<List<Volo.Abp.IdentityServer.ApiResources.ApiResource>, List<IdentityServer4.Models.ApiResource>>(apiResources),
ObjectMapper.Map<List<Volo.Abp.IdentityServer.ApiScopes.ApiScope>, List<IdentityServer4.Models.ApiScope>>(apiScopes));
}, () => new DistributedCacheEntryOptions
await cache.SetManyAsync(item, new DistributedCacheEntryOptions
{
AbsoluteExpirationRelativeToNow = Options.Caching.ClientStoreExpiration
});
}
protected virtual async Task<IEnumerable<TModel>> GetCacheItemsAsync<TEntity, TModel>(
IDistributedCache<TModel> cache,
IEnumerable<string> keys,
Func<string[], Task<List<TEntity>>> entityFactory,
Func<List<TModel>, string, List<IEnumerable<KeyValuePair<string, TModel>>>> 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<TEntity>, List<TModel>>(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<string> AddCachePrefix(IEnumerable<string> keys, string prefix)
{
return prefix == null ? keys : keys.Select(x => AddCachePrefix(x, prefix));
}
protected virtual IEnumerable<string> AddCachePrefix(IEnumerable<string> 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<string> RemoveCachePrefix(IEnumerable<string> keys, string prefix)
{
return prefix == null ? keys : keys.Select(x => RemoveCachePrefix(x, prefix));
}
protected virtual IEnumerable<string> RemoveCachePrefix(IEnumerable<string> 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);
}
}

45
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;
}
}
}

38
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<ApiResource> GetApiResources()
// {
// return new List<ApiResource>
// {
// new ApiResource("api1", "My API")
// };
// }
// public static IEnumerable<IdentityServer4.Models.Client> GetClients()
// {
// return new List<Client>
// {
// 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" }
// }
// };
// }
//}
}
namespace Volo.Abp.IdentityServer.Temp;

43
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<TokenCleanupOptions> options)
: base(
timer,
serviceScopeFactory)
{
Options = options.Value;
timer.Period = Options.CleanupPeriod;
}
public TokenCleanupBackgroundWorker(
AbpAsyncTimer timer,
IServiceScopeFactory serviceScopeFactory,
IOptions<TokenCleanupOptions> options)
: base(
timer,
serviceScopeFactory)
{
Options = options.Value;
timer.Period = Options.CleanupPeriod;
}
protected async override Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext)
{
await workerContext
.ServiceProvider
.GetRequiredService<TokenCleanupService>()
.CleanAsync();
}
protected async override Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext)
{
await workerContext
.ServiceProvider
.GetRequiredService<TokenCleanupService>()
.CleanAsync();
}
}

55
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
{
/// <summary>
/// Default: 3,600,000 ms.
/// </summary>
public int CleanupPeriod { get; set; } = 3_600_000;
/// <summary>
/// Default: 3,600,000 ms.
/// </summary>
public int CleanupPeriod { get; set; } = 3_600_000;
/// <summary>
/// Default value: 100.
/// </summary>
public int CleanupBatchSize { get; set; } = 100;
/// <summary>
/// Default value: 100.
/// </summary>
public int CleanupBatchSize { get; set; } = 100;
/// <summary>
/// The number of loop if there are
/// more than <see cref="CleanupBatchSize"/> tokens in the database.
/// So, if <see cref="CleanupLoopCount"/> is 10 and <see cref="CleanupBatchSize"/> is 100,
/// then the cleanup worker will clean 1,000 items in one <see cref="CleanupPeriod"/> at max.
///
/// Default value: 10.
/// </summary>
public int CleanupLoopCount { get; set; } = 10;
/// <summary>
/// The number of loop if there are
/// more than <see cref="CleanupBatchSize"/> tokens in the database.
/// So, if <see cref="CleanupLoopCount"/> is 10 and <see cref="CleanupBatchSize"/> is 100,
/// then the cleanup worker will clean 1,000 items in one <see cref="CleanupPeriod"/> at max.
///
/// Default value: 10.
/// </summary>
public int CleanupLoopCount { get; set; } = 10;
/// <summary>
/// Default value: true.
/// If <see cref="AbpBackgroundWorkerOptions.IsEnabled"/> is false,
/// this property is ignored and the cleanup worker doesn't work for this application instance.
/// </summary>
public bool IsCleanupEnabled { get; set; } = true;
}
}
/// <summary>
/// Default value: true.
/// If <see cref="AbpBackgroundWorkerOptions.IsEnabled"/> is false,
/// this property is ignored and the cleanup worker doesn't work for this application instance.
/// </summary>
public bool IsCleanupEnabled { get; set; } = true;
}

115
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<TokenCleanupOptions> 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<TokenCleanupOptions> 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;
}
}
}
}
}

25
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;
}
}
}

93
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<ApiResource> IncludeDetails(this IQueryable<ApiResource> queryable, bool include = true)
{
public static IQueryable<ApiResource> IncludeDetails(this IQueryable<ApiResource> 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<ApiScope> IncludeDetails(this IQueryable<ApiScope> 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<ApiScope> IncludeDetails(this IQueryable<ApiScope> queryable, bool include = true)
{
if (!include)
{
return queryable;
}
return queryable
.Include(x => x.UserClaims)
.Include(x => x.Properties);
}
public static IQueryable<IdentityResource> IncludeDetails(this IQueryable<IdentityResource> queryable, bool include = true)
{
if (!include)
{
return queryable;
}
return queryable
.Include(x => x.UserClaims)
.Include(x => x.Properties);
public static IQueryable<IdentityResource> IncludeDetails(this IQueryable<IdentityResource> queryable, bool include = true)
{
if (!include)
{
return queryable;
}
public static IQueryable<Client> IncludeDetails(this IQueryable<Client> 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<Client> IncludeDetails(this IQueryable<Client> 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);
}
}

181
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<IIdentityServerDbContext, ApiResource, Guid>, IApiResourceRepository
{
public class ApiResourceRepository : EfCoreRepository<IIdentityServerDbContext, ApiResource, Guid>, IApiResourceRepository
public ApiResourceRepository(IDbContextProvider<IIdentityServerDbContext> dbContextProvider) : base(dbContextProvider)
{
public ApiResourceRepository(IDbContextProvider<IIdentityServerDbContext> dbContextProvider) : base(dbContextProvider)
{
}
}
public async Task<ApiResource> 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<ApiResource> 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<List<ApiResource>> 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<List<ApiResource>> 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<List<ApiResource>> 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<List<ApiResource>> 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<List<ApiResource>> 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<List<ApiResource>> 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<long> 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<long> 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<bool> 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<bool> 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<ApiResourceClaim>().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<ApiResourceClaim>().Remove(scopeClaim);
}
public async override Task DeleteAsync(Guid id, bool autoSave = false, CancellationToken cancellationToken = default)
var resourceScopes = dbContext.Set<ApiResourceScope>().Where(s => s.ApiResourceId == id);
foreach (var scope in resourceScopes)
{
var dbContext = await GetDbContextAsync();
var resourceClaims = dbContext.Set<ApiResourceClaim>().Where(sc => sc.ApiResourceId == id);
foreach (var scopeClaim in resourceClaims)
{
dbContext.Set<ApiResourceClaim>().Remove(scopeClaim);
}
var resourceScopes = dbContext.Set<ApiResourceScope>().Where(s => s.ApiResourceId == id);
foreach (var scope in resourceScopes)
{
dbContext.Set<ApiResourceScope>().Remove(scope);
}
var resourceSecrets = dbContext.Set<ApiResourceSecret>().Where(s => s.ApiResourceId == id);
foreach (var secret in resourceSecrets)
{
dbContext.Set<ApiResourceSecret>().Remove(secret);
}
var apiResourceProperties = dbContext.Set<ApiResourceProperty>().Where(s => s.ApiResourceId == id);
foreach (var property in apiResourceProperties)
{
dbContext.Set<ApiResourceProperty>().Remove(property);
}
await base.DeleteAsync(id, autoSave, cancellationToken);
dbContext.Set<ApiResourceScope>().Remove(scope);
}
[Obsolete("Use WithDetailsAsync method.")]
public override IQueryable<ApiResource> WithDetails()
var resourceSecrets = dbContext.Set<ApiResourceSecret>().Where(s => s.ApiResourceId == id);
foreach (var secret in resourceSecrets)
{
return GetQueryable().IncludeDetails();
dbContext.Set<ApiResourceSecret>().Remove(secret);
}
public override async Task<IQueryable<ApiResource>> WithDetailsAsync()
var apiResourceProperties = dbContext.Set<ApiResourceProperty>().Where(s => s.ApiResourceId == id);
foreach (var property in apiResourceProperties)
{
return (await GetQueryableAsync()).IncludeDetails();
dbContext.Set<ApiResourceProperty>().Remove(property);
}
await base.DeleteAsync(id, autoSave, cancellationToken);
}
[Obsolete("Use WithDetailsAsync method.")]
public override IQueryable<ApiResource> WithDetails()
{
return GetQueryable().IncludeDetails();
}
public override async Task<IQueryable<ApiResource>> WithDetailsAsync()
{
return (await GetQueryableAsync()).IncludeDetails();
}
}

135
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<IIdentityServerDbContext, ApiScope, Guid>, IApiScopeRepository
{
public class ApiScopeRepository : EfCoreRepository<IIdentityServerDbContext, ApiScope, Guid>, IApiScopeRepository
public ApiScopeRepository(IDbContextProvider<IIdentityServerDbContext> dbContextProvider) : base(
dbContextProvider)
{
public ApiScopeRepository(IDbContextProvider<IIdentityServerDbContext> dbContextProvider) : base(
dbContextProvider)
{
}
}
public async Task<ApiScope> 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<ApiScope> 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<List<ApiScope>> 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<List<ApiScope>> 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<List<ApiScope>> 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<List<ApiScope>> 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<long> 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<long> 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<bool> 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<bool> 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<ApiScopeClaim>().Where(sc => sc.ApiScopeId == id);
foreach (var claim in scopeClaims)
{
var dbContext = await GetDbContextAsync();
var scopeClaims = dbContext.Set<ApiScopeClaim>().Where(sc => sc.ApiScopeId == id);
foreach (var claim in scopeClaims)
{
dbContext.Set<ApiScopeClaim>().Remove(claim);
}
var scopeProperties = dbContext.Set<ApiScopeProperty>().Where(s => s.ApiScopeId == id);
foreach (var property in scopeProperties)
{
dbContext.Set<ApiScopeProperty>().Remove(property);
}
await base.DeleteAsync(id, autoSave, cancellationToken);
dbContext.Set<ApiScopeClaim>().Remove(claim);
}
[Obsolete("Use WithDetailsAsync method.")]
public override IQueryable<ApiScope> WithDetails()
var scopeProperties = dbContext.Set<ApiScopeProperty>().Where(s => s.ApiScopeId == id);
foreach (var property in scopeProperties)
{
return GetQueryable().IncludeDetails();
dbContext.Set<ApiScopeProperty>().Remove(property);
}
public override async Task<IQueryable<ApiScope>> WithDetailsAsync()
{
return (await GetQueryableAsync()).IncludeDetails();
}
await base.DeleteAsync(id, autoSave, cancellationToken);
}
[Obsolete("Use WithDetailsAsync method.")]
public override IQueryable<ApiScope> WithDetails()
{
return GetQueryable().IncludeDetails();
}
public override async Task<IQueryable<ApiScope>> WithDetailsAsync()
{
return (await GetQueryableAsync()).IncludeDetails();
}
}

171
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<IIdentityServerDbContext, Client, Guid>, IClientRepository
{
public class ClientRepository : EfCoreRepository<IIdentityServerDbContext, Client, Guid>, IClientRepository
public ClientRepository(IDbContextProvider<IIdentityServerDbContext> dbContextProvider) : base(dbContextProvider)
{
public ClientRepository(IDbContextProvider<IIdentityServerDbContext> dbContextProvider) : base(dbContextProvider)
{
}
public virtual async Task<Client> 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<List<Client>> 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<long> 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<List<string>> GetAllDistinctAllowedCorsOriginsAsync(CancellationToken cancellationToken = default)
{
return await (await GetDbContextAsync()).ClientCorsOrigins
.Select(x => x.Origin)
.Distinct()
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<bool> 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<ClientGrantType>().Where(x => x.ClientId == id))
{
dbContext.Set<ClientGrantType>().Remove(clientGrantType);
}
public virtual async Task<Client> FindByClientIdAsync(
string clientId,
bool includeDetails = true,
CancellationToken cancellationToken = default)
foreach (var clientRedirectUri in dbContext.Set<ClientRedirectUri>().Where(x => x.ClientId == id))
{
return await (await GetDbSetAsync())
.IncludeDetails(includeDetails)
.OrderBy(x => x.ClientId)
.FirstOrDefaultAsync(x => x.ClientId == clientId, GetCancellationToken(cancellationToken));
dbContext.Set<ClientRedirectUri>().Remove(clientRedirectUri);
}
public virtual async Task<List<Client>> GetListAsync(
string sorting, int skipCount, int maxResultCount, string filter, bool includeDetails = false,
CancellationToken cancellationToken = default)
foreach (var clientPostLogoutRedirectUri in dbContext.Set<ClientPostLogoutRedirectUri>().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<ClientPostLogoutRedirectUri>().Remove(clientPostLogoutRedirectUri);
}
public async Task<long> GetCountAsync(string filter = null, CancellationToken cancellationToken = default)
foreach (var clientScope in dbContext.Set<ClientScope>().Where(x => x.ClientId == id))
{
return await (await GetDbSetAsync())
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.ClientId.Contains(filter))
.LongCountAsync(GetCancellationToken(cancellationToken));
dbContext.Set<ClientScope>().Remove(clientScope);
}
public virtual async Task<List<string>> GetAllDistinctAllowedCorsOriginsAsync(CancellationToken cancellationToken = default)
foreach (var clientSecret in dbContext.Set<ClientSecret>().Where(x => x.ClientId == id))
{
return await (await GetDbContextAsync()).ClientCorsOrigins
.Select(x => x.Origin)
.Distinct()
.ToListAsync(GetCancellationToken(cancellationToken));
dbContext.Set<ClientSecret>().Remove(clientSecret);
}
public virtual async Task<bool> CheckClientIdExistAsync(string clientId, Guid? expectedId = null, CancellationToken cancellationToken = default)
foreach (var clientClaim in dbContext.Set<ClientClaim>().Where(x => x.ClientId == id))
{
return await (await GetDbSetAsync()).AnyAsync(c => c.Id != expectedId && c.ClientId == clientId, GetCancellationToken(cancellationToken));
dbContext.Set<ClientClaim>().Remove(clientClaim);
}
public async override Task DeleteAsync(Guid id, bool autoSave = false, CancellationToken cancellationToken = default)
foreach (var clientIdPRestriction in dbContext.Set<ClientIdPRestriction>().Where(x => x.ClientId == id))
{
var dbContext = await GetDbContextAsync();
foreach (var clientGrantType in dbContext.Set<ClientGrantType>().Where(x => x.ClientId == id))
{
dbContext.Set<ClientGrantType>().Remove(clientGrantType);
}
foreach (var clientRedirectUri in dbContext.Set<ClientRedirectUri>().Where(x => x.ClientId == id))
{
dbContext.Set<ClientRedirectUri>().Remove(clientRedirectUri);
}
foreach (var clientPostLogoutRedirectUri in dbContext.Set<ClientPostLogoutRedirectUri>().Where(x => x.ClientId == id))
{
dbContext.Set<ClientPostLogoutRedirectUri>().Remove(clientPostLogoutRedirectUri);
}
foreach (var clientScope in dbContext.Set<ClientScope>().Where(x => x.ClientId == id))
{
dbContext.Set<ClientScope>().Remove(clientScope);
}
foreach (var clientSecret in dbContext.Set<ClientSecret>().Where(x => x.ClientId == id))
{
dbContext.Set<ClientSecret>().Remove(clientSecret);
}
foreach (var clientClaim in dbContext.Set<ClientClaim>().Where(x => x.ClientId == id))
{
dbContext.Set<ClientClaim>().Remove(clientClaim);
}
foreach (var clientIdPRestriction in dbContext.Set<ClientIdPRestriction>().Where(x => x.ClientId == id))
{
dbContext.Set<ClientIdPRestriction>().Remove(clientIdPRestriction);
}
foreach (var clientCorsOrigin in dbContext.Set<ClientCorsOrigin>().Where(x => x.ClientId == id))
{
dbContext.Set<ClientCorsOrigin>().Remove(clientCorsOrigin);
}
foreach (var clientProperty in dbContext.Set<ClientProperty>().Where(x => x.ClientId == id))
{
dbContext.Set<ClientProperty>().Remove(clientProperty);
}
await base.DeleteAsync(id, autoSave, cancellationToken);
dbContext.Set<ClientIdPRestriction>().Remove(clientIdPRestriction);
}
[Obsolete("Use WithDetailsAsync method.")]
public override IQueryable<Client> WithDetails()
foreach (var clientCorsOrigin in dbContext.Set<ClientCorsOrigin>().Where(x => x.ClientId == id))
{
return GetQueryable().IncludeDetails();
dbContext.Set<ClientCorsOrigin>().Remove(clientCorsOrigin);
}
public override async Task<IQueryable<Client>> WithDetailsAsync()
foreach (var clientProperty in dbContext.Set<ClientProperty>().Where(x => x.ClientId == id))
{
return (await GetQueryableAsync()).IncludeDetails();
dbContext.Set<ClientProperty>().Remove(clientProperty);
}
await base.DeleteAsync(id, autoSave, cancellationToken);
}
[Obsolete("Use WithDetailsAsync method.")]
public override IQueryable<Client> WithDetails()
{
return GetQueryable().IncludeDetails();
}
public override async Task<IQueryable<Client>> WithDetailsAsync()
{
return (await GetQueryableAsync()).IncludeDetails();
}
}

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save