Browse Source

feat(identity): Add anonymous sessions

pull/1256/head
colin 7 months ago
parent
commit
f9c2f8a168
  1. 12
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session/LINGYUN/Abp/Identity/Session/AllowAnonymousIdentitySessionChecker.cs
  2. 22
      aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session/Microsoft/Extensions/DependencyInjection/IdentitySessionServiceCollectionExtensions.cs

12
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<bool> ValidateSessionAsync(ClaimsPrincipal claimsPrincipal, CancellationToken cancellationToken = default)
{
return Task.FromResult(true);
}
}

22
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
{
/// <summary>
/// 允许任意会话
/// </summary>
/// <remarks>
/// 某些场景下可能缓存配置不同,可不检查会话缓存
/// </remarks>
/// <param name="services"></param>
/// <returns></returns>
public static IServiceCollection AddAlwaysAllowSession(this IServiceCollection services)
{
services.Replace(
ServiceDescriptor.Singleton<IIdentitySessionChecker, AllowAnonymousIdentitySessionChecker>());
return services;
}
}
Loading…
Cancel
Save