From f9c2f8a1681407d43ae23b8caee055aeda83c34c Mon Sep 17 00:00:00 2001 From: colin Date: Wed, 2 Jul 2025 08:15:10 +0800 Subject: [PATCH] feat(identity): Add anonymous sessions --- .../AllowAnonymousIdentitySessionChecker.cs | 12 ++++++++++ ...ntitySessionServiceCollectionExtensions.cs | 22 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session/LINGYUN/Abp/Identity/Session/AllowAnonymousIdentitySessionChecker.cs create mode 100644 aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session/Microsoft/Extensions/DependencyInjection/IdentitySessionServiceCollectionExtensions.cs diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session/LINGYUN/Abp/Identity/Session/AllowAnonymousIdentitySessionChecker.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session/LINGYUN/Abp/Identity/Session/AllowAnonymousIdentitySessionChecker.cs new file mode 100644 index 000000000..bac6f1872 --- /dev/null +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session/LINGYUN/Abp/Identity/Session/AllowAnonymousIdentitySessionChecker.cs @@ -0,0 +1,12 @@ +using System.Security.Claims; +using System.Threading; +using System.Threading.Tasks; + +namespace LINGYUN.Abp.Identity.Session; +public class AllowAnonymousIdentitySessionChecker : IIdentitySessionChecker +{ + public Task ValidateSessionAsync(ClaimsPrincipal claimsPrincipal, CancellationToken cancellationToken = default) + { + return Task.FromResult(true); + } +} diff --git a/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session/Microsoft/Extensions/DependencyInjection/IdentitySessionServiceCollectionExtensions.cs b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session/Microsoft/Extensions/DependencyInjection/IdentitySessionServiceCollectionExtensions.cs new file mode 100644 index 000000000..2e7154f03 --- /dev/null +++ b/aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session/Microsoft/Extensions/DependencyInjection/IdentitySessionServiceCollectionExtensions.cs @@ -0,0 +1,22 @@ +using LINGYUN.Abp.Identity.Session; +using Microsoft.Extensions.DependencyInjection.Extensions; + +namespace Microsoft.Extensions.DependencyInjection; +public static class IdentitySessionServiceCollectionExtensions +{ + /// + /// 允许任意会话 + /// + /// + /// 某些场景下可能缓存配置不同,可不检查会话缓存 + /// + /// + /// + public static IServiceCollection AddAlwaysAllowSession(this IServiceCollection services) + { + services.Replace( + ServiceDescriptor.Singleton()); + + return services; + } +}