From 07ab77781432ca231bd7ee333d8bcefa6b3db983 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Wed, 6 Dec 2023 19:07:16 +0800 Subject: [PATCH] Keep the claims when refreshing principal --- .../AspNetCore/AbpIdentityAspNetCoreModule.cs | 9 +++++++++ .../SecurityStampValidatorOptionsExtensions.cs | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/SecurityStampValidatorOptionsExtensions.cs diff --git a/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpIdentityAspNetCoreModule.cs b/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpIdentityAspNetCoreModule.cs index 974f81a201..9b38e2e25a 100644 --- a/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpIdentityAspNetCoreModule.cs +++ b/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/AbpIdentityAspNetCoreModule.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Modularity; +using static Volo.Abp.Identity.AspNetCore.AbpSecurityStampValidatorCallback; namespace Volo.Abp.Identity.AspNetCore; @@ -41,4 +42,12 @@ public class AbpIdentityAspNetCoreModule : AbpModule .AddIdentityCookies(); } } + + public override void PostConfigureServices(ServiceConfigurationContext context) + { + Configure(options => + { + options.UpdatePrincipal(); + }); + } } diff --git a/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/SecurityStampValidatorOptionsExtensions.cs b/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/SecurityStampValidatorOptionsExtensions.cs new file mode 100644 index 0000000000..4d1a26b03c --- /dev/null +++ b/modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore/SecurityStampValidatorOptionsExtensions.cs @@ -0,0 +1,18 @@ +using Microsoft.AspNetCore.Identity; +using static Volo.Abp.Identity.AspNetCore.AbpSecurityStampValidatorCallback; + +namespace Volo.Abp.Identity.AspNetCore; + +public static class SecurityStampValidatorOptionsExtensions +{ + public static SecurityStampValidatorOptions UpdatePrincipal(this SecurityStampValidatorOptions options) + { + var previousOnRefreshingPrincipal = options.OnRefreshingPrincipal; + options.OnRefreshingPrincipal = async context => + { + await SecurityStampValidatorCallback.UpdatePrincipal(context); + await previousOnRefreshingPrincipal?.Invoke(context); + }; + return options; + } +}