committed by
GitHub
126 changed files with 649 additions and 1628 deletions
@ -0,0 +1,15 @@ |
|||
using LINGYUN.Abp.Identity.Session; |
|||
using LINGYUN.Abp.IP.Location; |
|||
using Volo.Abp.AspNetCore; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace LINGYUN.Abp.AspNetCore.Session; |
|||
|
|||
[DependsOn( |
|||
typeof(AbpIdentitySessionModule), |
|||
typeof(AbpIPLocationModule), |
|||
typeof(AbpAspNetCoreModule))] |
|||
public class AbpAspNetCoreSessionModule : AbpModule |
|||
{ |
|||
|
|||
} |
|||
@ -1,12 +1,13 @@ |
|||
namespace LINGYUN.Abp.Identity.Session.AspNetCore; |
|||
public class AbpIdentitySessionAspNetCoreOptions |
|||
namespace LINGYUN.Abp.AspNetCore.Session; |
|||
|
|||
public class AbpAspNetCoreSessionOptions |
|||
{ |
|||
/// <summary>
|
|||
/// 是否解析IP地理信息
|
|||
/// </summary>
|
|||
public bool IsParseIpLocation { get; set; } |
|||
|
|||
public AbpIdentitySessionAspNetCoreOptions() |
|||
public AbpAspNetCoreSessionOptions() |
|||
{ |
|||
IsParseIpLocation = false; |
|||
} |
|||
6
aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session.AspNetCore/LINGYUN/Abp/Identity/Session/AspNetCore/AbpIdentitySessionDynamicClaimsPrincipalContributor.cs → aspnet-core/framework/common/LINGYUN.Abp.AspNetCore.Session/LINGYUN/Abp/AspNetCore/Session/AbpIdentitySessionDynamicClaimsPrincipalContributor.cs
6
aspnet-core/modules/identity/LINGYUN.Abp.Identity.Session.AspNetCore/LINGYUN/Abp/Identity/Session/AspNetCore/AbpIdentitySessionDynamicClaimsPrincipalContributor.cs → aspnet-core/framework/common/LINGYUN.Abp.AspNetCore.Session/LINGYUN/Abp/AspNetCore/Session/AbpIdentitySessionDynamicClaimsPrincipalContributor.cs
@ -0,0 +1,102 @@ |
|||
//using IdentityServer4.Events;
|
|||
//using LINGYUN.Abp.Identity.Session;
|
|||
//using System;
|
|||
//using System.Security.Claims;
|
|||
//using System.Threading.Tasks;
|
|||
//using Volo.Abp.DependencyInjection;
|
|||
//using Volo.Abp.MultiTenancy;
|
|||
//using Volo.Abp.Security.Claims;
|
|||
//using Volo.Abp.Uow;
|
|||
|
|||
//namespace LINGYUN.Abp.IdentityServer.Session;
|
|||
///// <summary>
|
|||
///// 持久化用户会话
|
|||
///// </summary>
|
|||
//public class AbpIdentitySessionEventServiceHandler : IAbpIdentityServerEventServiceHandler, ITransientDependency
|
|||
//{
|
|||
// protected ICurrentTenant CurrentTenant { get; }
|
|||
// protected ISessionInfoProvider SessionInfoProvider { get; }
|
|||
// protected IIdentitySessionManager IdentitySessionManager { get; }
|
|||
// protected ICurrentPrincipalAccessor CurrentPrincipalAccessor { get; }
|
|||
|
|||
// public AbpIdentitySessionEventServiceHandler(
|
|||
// ICurrentTenant currentTenant,
|
|||
// ISessionInfoProvider sessionInfoProvider,
|
|||
// IIdentitySessionManager identitySessionManager,
|
|||
// ICurrentPrincipalAccessor currentPrincipalAccessor)
|
|||
// {
|
|||
// CurrentTenant = currentTenant;
|
|||
// SessionInfoProvider = sessionInfoProvider;
|
|||
// IdentitySessionManager = identitySessionManager;
|
|||
// CurrentPrincipalAccessor = currentPrincipalAccessor;
|
|||
// }
|
|||
|
|||
// public virtual bool CanRaiseEventType(EventTypes evtType)
|
|||
// {
|
|||
// return evtType == EventTypes.Success;
|
|||
// }
|
|||
|
|||
// [UnitOfWork]
|
|||
// public virtual Task RaiseAsync(Event evt)
|
|||
// {
|
|||
// if (evt is UserLoginSuccessEvent loginEvent)
|
|||
// {
|
|||
// // 用户登录事件
|
|||
// return RaiseUserLoginSuccessEventAsync(loginEvent);
|
|||
// }
|
|||
// if (evt is UserLogoutSuccessEvent logoutEvent)
|
|||
// {
|
|||
// // 用户退出事件
|
|||
// return RaiseUserLogoutSuccessEventAsync(logoutEvent);
|
|||
// }
|
|||
// if (evt is TokenRevokedSuccessEvent revokeEvent)
|
|||
// {
|
|||
// // 撤销令牌事件
|
|||
// return RaiseTokenRevokedSuccessEventAsync(revokeEvent);
|
|||
// }
|
|||
// return Task.CompletedTask;
|
|||
// }
|
|||
|
|||
// protected async virtual Task RaiseUserLoginSuccessEventAsync(UserLoginSuccessEvent loginEvent)
|
|||
// {
|
|||
// var subjectId = loginEvent.SubjectId;
|
|||
// var sessionId = SessionInfoProvider.SessionId;
|
|||
// if (!sessionId.IsNullOrWhiteSpace() &&
|
|||
// Guid.TryParse(subjectId, out var userId))
|
|||
// {
|
|||
// var claimsIdentity = new ClaimsIdentity();
|
|||
// claimsIdentity.AddClaim(new Claim(AbpClaimTypes.UserId, userId.ToString()));
|
|||
// claimsIdentity.AddClaim(new Claim(AbpClaimTypes.SessionId, sessionId));
|
|||
// if (!loginEvent.ClientId.IsNullOrWhiteSpace())
|
|||
// {
|
|||
// claimsIdentity.AddClaim(new Claim(AbpClaimTypes.ClientId, loginEvent.ClientId));
|
|||
// }
|
|||
// if (CurrentTenant.IsAvailable)
|
|||
// {
|
|||
// claimsIdentity.AddClaim(new Claim(AbpClaimTypes.TenantId, CurrentTenant.Id!.Value.ToString()));
|
|||
// }
|
|||
// var claimsPrincipal = new ClaimsPrincipal(claimsIdentity);
|
|||
// using (CurrentPrincipalAccessor.Change(claimsPrincipal))
|
|||
// {
|
|||
// await IdentitySessionManager.SaveSessionAsync(claimsPrincipal);
|
|||
// }
|
|||
// }
|
|||
// }
|
|||
// protected async virtual Task RaiseUserLogoutSuccessEventAsync(UserLogoutSuccessEvent logoutEvent)
|
|||
// {
|
|||
// var sessionId = SessionInfoProvider.SessionId;
|
|||
// if (!sessionId.IsNullOrWhiteSpace())
|
|||
// {
|
|||
// await IdentitySessionManager.RevokeSessionAsync(sessionId);
|
|||
// }
|
|||
// }
|
|||
|
|||
// protected async virtual Task RaiseTokenRevokedSuccessEventAsync(TokenRevokedSuccessEvent revokeEvent)
|
|||
// {
|
|||
// var sessionId = SessionInfoProvider.SessionId;
|
|||
// if (!sessionId.IsNullOrWhiteSpace())
|
|||
// {
|
|||
// await IdentitySessionManager.RevokeSessionAsync(sessionId);
|
|||
// }
|
|||
// }
|
|||
//}
|
|||
@ -1,7 +1,7 @@ |
|||
using IdentityModel; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace LINGYUN.Abp.IdentityServer.Session; |
|||
namespace LINGYUN.Abp.Account.Web.IdentityServer.Handlers; |
|||
internal static class Constants |
|||
{ |
|||
public static Dictionary<string, int> ProtectedResourceErrorStatusCodes = new Dictionary<string, int> |
|||
@ -0,0 +1,114 @@ |
|||
using Duende.IdentityModel; |
|||
using LINGYUN.Abp.Identity.Session; |
|||
using Microsoft.AspNetCore.Authentication; |
|||
using Microsoft.AspNetCore.Http; |
|||
using Microsoft.AspNetCore.WebUtilities; |
|||
using Microsoft.Extensions.Options; |
|||
using System; |
|||
using System.Linq; |
|||
using System.Security.Claims; |
|||
using System.Security.Principal; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Security.Claims; |
|||
|
|||
namespace LINGYUN.Abp.Account.Web.IdentityServer.Services; |
|||
|
|||
public class IdentityServerSessionAuthenticationService : AuthenticationService |
|||
{ |
|||
protected IIdentitySessionManager IdentitySessionManager { get; } |
|||
|
|||
public IdentityServerSessionAuthenticationService( |
|||
IAuthenticationSchemeProvider schemes, |
|||
IAuthenticationHandlerProvider handlers, |
|||
IClaimsTransformation transform, |
|||
IOptions<AuthenticationOptions> options, |
|||
IIdentitySessionManager identitySessionManager) : base(schemes, handlers, transform, options) |
|||
{ |
|||
IdentitySessionManager = identitySessionManager; |
|||
} |
|||
|
|||
public async override Task SignInAsync(HttpContext context, string? scheme, ClaimsPrincipal principal, AuthenticationProperties? properties) |
|||
{ |
|||
var claimsIdentity = principal.Identities.FirstOrDefault(); |
|||
if (claimsIdentity == null || !claimsIdentity.FindSessionId().IsNullOrWhiteSpace()) |
|||
{ |
|||
await base.SignInAsync(context, scheme, principal, properties); |
|||
return; |
|||
} |
|||
|
|||
claimsIdentity.AddClaim(new Claim(AbpClaimTypes.SessionId, Guid.NewGuid().ToString())); |
|||
|
|||
var clientId = principal.FindClientId(); |
|||
if (clientId.IsNullOrWhiteSpace()) |
|||
{ |
|||
// 从授权回调中获取客户端Id
|
|||
clientId = FindClientId(context); |
|||
} |
|||
|
|||
await base.SignInAsync(context, scheme, principal, properties); |
|||
|
|||
await IdentitySessionManager.SaveSessionAsync(clientId, principal, context.RequestAborted); |
|||
} |
|||
|
|||
public async override Task SignOutAsync(HttpContext context, string? scheme, AuthenticationProperties? properties) |
|||
{ |
|||
var sessionId = context.User?.FindSessionId(); |
|||
if (!sessionId.IsNullOrWhiteSpace()) |
|||
{ |
|||
// Revoke the user session.
|
|||
await IdentitySessionManager.RevokeSessionAsync(sessionId, context.RequestAborted); |
|||
} |
|||
|
|||
await base.SignOutAsync(context, scheme, properties); |
|||
} |
|||
|
|||
private static string? FindClientId(HttpContext context) |
|||
{ |
|||
if (context.Request.Query.TryGetValue("ReturnUrl", out var queryReturnUrls)) |
|||
{ |
|||
var clientId = GetQueryValue(queryReturnUrls.FirstOrDefault()); |
|||
if (!clientId.IsNullOrWhiteSpace()) |
|||
{ |
|||
return clientId; |
|||
} |
|||
} |
|||
|
|||
if (context.Request.Form.TryGetValue("ReturnUrl", out var formReturnUrls)) |
|||
{ |
|||
var clientId = GetQueryValue(formReturnUrls.FirstOrDefault()); |
|||
if (!clientId.IsNullOrWhiteSpace()) |
|||
{ |
|||
return clientId; |
|||
} |
|||
} |
|||
|
|||
if (context.Request.Query.TryGetValue(JwtClaimTypes.ClientId, out var queryClientIds)) |
|||
{ |
|||
return queryClientIds.FirstOrDefault(); |
|||
} |
|||
|
|||
if (context.Request.Form.TryGetValue(JwtClaimTypes.ClientId, out var formClientIds)) |
|||
{ |
|||
return formClientIds.FirstOrDefault(); |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
private static string? GetQueryValue(string? returnUrls) |
|||
{ |
|||
if (string.IsNullOrWhiteSpace(returnUrls)) |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
if (returnUrls.Contains('?')) |
|||
{ |
|||
returnUrls = returnUrls.Split('?')[1]; |
|||
} |
|||
|
|||
var parameters = QueryHelpers.ParseQuery(returnUrls); |
|||
|
|||
return parameters.TryGetValue(JwtClaimTypes.ClientId, out var clientId) ? clientId.ToString() : null; |
|||
} |
|||
} |
|||
@ -0,0 +1,114 @@ |
|||
using Duende.IdentityModel; |
|||
using LINGYUN.Abp.Identity.Session; |
|||
using Microsoft.AspNetCore.Authentication; |
|||
using Microsoft.AspNetCore.Http; |
|||
using Microsoft.AspNetCore.WebUtilities; |
|||
using Microsoft.Extensions.Options; |
|||
using System; |
|||
using System.Linq; |
|||
using System.Security.Claims; |
|||
using System.Security.Principal; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Security.Claims; |
|||
|
|||
namespace LINGYUN.Abp.Account.Web.OpenIddict.Services; |
|||
|
|||
public class OpenIddictSessionAuthenticationService : AuthenticationService |
|||
{ |
|||
protected IIdentitySessionManager IdentitySessionManager { get; } |
|||
|
|||
public OpenIddictSessionAuthenticationService( |
|||
IAuthenticationSchemeProvider schemes, |
|||
IAuthenticationHandlerProvider handlers, |
|||
IClaimsTransformation transform, |
|||
IOptions<AuthenticationOptions> options, |
|||
IIdentitySessionManager identitySessionManager) : base(schemes, handlers, transform, options) |
|||
{ |
|||
IdentitySessionManager = identitySessionManager; |
|||
} |
|||
|
|||
public async override Task SignInAsync(HttpContext context, string? scheme, ClaimsPrincipal principal, AuthenticationProperties? properties) |
|||
{ |
|||
var claimsIdentity = principal.Identities.FirstOrDefault(); |
|||
if (claimsIdentity == null || !claimsIdentity.FindSessionId().IsNullOrWhiteSpace()) |
|||
{ |
|||
await base.SignInAsync(context, scheme, principal, properties); |
|||
return; |
|||
} |
|||
|
|||
claimsIdentity.AddClaim(new Claim(AbpClaimTypes.SessionId, Guid.NewGuid().ToString())); |
|||
|
|||
var clientId = principal.FindClientId(); |
|||
if (clientId.IsNullOrWhiteSpace()) |
|||
{ |
|||
// 从授权回调中获取客户端Id
|
|||
clientId = FindClientId(context); |
|||
} |
|||
|
|||
await base.SignInAsync(context, scheme, principal, properties); |
|||
|
|||
await IdentitySessionManager.SaveSessionAsync(clientId, principal, context.RequestAborted); |
|||
} |
|||
|
|||
public async override Task SignOutAsync(HttpContext context, string? scheme, AuthenticationProperties? properties) |
|||
{ |
|||
var sessionId = context.User?.FindSessionId(); |
|||
if (!sessionId.IsNullOrWhiteSpace()) |
|||
{ |
|||
// Revoke the user session.
|
|||
await IdentitySessionManager.RevokeSessionAsync(sessionId, context.RequestAborted); |
|||
} |
|||
|
|||
await base.SignOutAsync(context, scheme, properties); |
|||
} |
|||
|
|||
private static string? FindClientId(HttpContext context) |
|||
{ |
|||
if (context.Request.Query.TryGetValue("ReturnUrl", out var queryReturnUrls)) |
|||
{ |
|||
var clientId = GetQueryValue(queryReturnUrls.FirstOrDefault()); |
|||
if (!clientId.IsNullOrWhiteSpace()) |
|||
{ |
|||
return clientId; |
|||
} |
|||
} |
|||
|
|||
if (context.Request.Form.TryGetValue("ReturnUrl", out var formReturnUrls)) |
|||
{ |
|||
var clientId = GetQueryValue(formReturnUrls.FirstOrDefault()); |
|||
if (!clientId.IsNullOrWhiteSpace()) |
|||
{ |
|||
return clientId; |
|||
} |
|||
} |
|||
|
|||
if (context.Request.Query.TryGetValue(JwtClaimTypes.ClientId, out var queryClientIds)) |
|||
{ |
|||
return queryClientIds.FirstOrDefault(); |
|||
} |
|||
|
|||
if (context.Request.Form.TryGetValue(JwtClaimTypes.ClientId, out var formClientIds)) |
|||
{ |
|||
return formClientIds.FirstOrDefault(); |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
private static string? GetQueryValue(string? returnUrls) |
|||
{ |
|||
if (string.IsNullOrWhiteSpace(returnUrls)) |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
if (returnUrls.Contains('?')) |
|||
{ |
|||
returnUrls = returnUrls.Split('?')[1]; |
|||
} |
|||
|
|||
var parameters = QueryHelpers.ParseQuery(returnUrls); |
|||
|
|||
return parameters.TryGetValue(JwtClaimTypes.ClientId, out var clientId) ? clientId.ToString() : null; |
|||
} |
|||
} |
|||
@ -1,24 +0,0 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\..\..\configureawait.props" /> |
|||
<Import Project="..\..\..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>net10.0</TargetFramework> |
|||
<AssemblyName>LINGYUN.Abp.Identity.AspNetCore.Session</AssemblyName> |
|||
<PackageId>LINGYUN.Abp.Identity.AspNetCore.Session</PackageId> |
|||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
|||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
|||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Volo.Abp.Identity.AspNetCore" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\LINGYUN.Abp.Identity.Domain\LINGYUN.Abp.Identity.Domain.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -1,26 +0,0 @@ |
|||
using Microsoft.AspNetCore.Authentication; |
|||
using Microsoft.AspNetCore.Identity; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.Identity.AspNetCore; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace LINGYUN.Abp.Identity.AspNetCore.Session; |
|||
|
|||
[DependsOn( |
|||
typeof(AbpIdentityAspNetCoreModule), |
|||
typeof(AbpIdentityDomainModule))] |
|||
public class AbpIdentityAspNetCoreSessionModule : AbpModule |
|||
{ |
|||
public override void PreConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
PreConfigure<IdentityBuilder>(builder => |
|||
{ |
|||
// builder.AddSignInManager<AbpIdentitySessionSignInManager>();
|
|||
}); |
|||
} |
|||
|
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
context.Services.AddTransient<IAuthenticationService, AbpIdentitySessionAuthenticationService>(); |
|||
} |
|||
} |
|||
@ -1,58 +0,0 @@ |
|||
using LINGYUN.Abp.Identity.Session; |
|||
using Microsoft.AspNetCore.Authentication; |
|||
using Microsoft.AspNetCore.Http; |
|||
using Microsoft.Extensions.Options; |
|||
using System; |
|||
using System.Security.Claims; |
|||
using System.Security.Principal; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.Identity.AspNetCore.Session; |
|||
|
|||
public class AbpIdentitySessionAuthenticationService : AuthenticationService |
|||
{ |
|||
protected IdentitySessionSignInOptions SessionSignInOptions { get; } |
|||
protected IIdentitySessionManager IdentitySessionManager { get; } |
|||
|
|||
public AbpIdentitySessionAuthenticationService( |
|||
IAuthenticationSchemeProvider schemes, |
|||
IAuthenticationHandlerProvider handlers, |
|||
IClaimsTransformation transform, |
|||
IOptions<AuthenticationOptions> options, |
|||
IIdentitySessionManager identitySessionManager, |
|||
IOptions<IdentitySessionSignInOptions> sessionSignInOptions) : base(schemes, handlers, transform, options) |
|||
{ |
|||
SessionSignInOptions = sessionSignInOptions.Value; |
|||
IdentitySessionManager = identitySessionManager; |
|||
} |
|||
|
|||
public async override Task SignInAsync(HttpContext context, string? scheme, ClaimsPrincipal principal, AuthenticationProperties? properties) |
|||
{ |
|||
await base.SignInAsync(context, scheme, principal, properties); |
|||
|
|||
if (SessionSignInOptions.SignInSessionEnabled && |
|||
!scheme.IsNullOrWhiteSpace() && |
|||
SessionSignInOptions.AuthenticationSchemes.Contains(scheme)) |
|||
{ |
|||
// Save the user session.
|
|||
await IdentitySessionManager.SaveSessionAsync(principal); |
|||
} |
|||
} |
|||
|
|||
public async override Task SignOutAsync(HttpContext context, string? scheme, AuthenticationProperties? properties) |
|||
{ |
|||
if (SessionSignInOptions.SignOutSessionEnabled && |
|||
!scheme.IsNullOrWhiteSpace() && |
|||
SessionSignInOptions.AuthenticationSchemes.Contains(scheme)) |
|||
{ |
|||
var sessionId = context.User?.FindSessionId(); |
|||
if (!sessionId.IsNullOrWhiteSpace()) |
|||
{ |
|||
// Revoke the user session.
|
|||
await IdentitySessionManager.RevokeSessionAsync(sessionId); |
|||
} |
|||
} |
|||
|
|||
await base.SignOutAsync(context, scheme, properties); |
|||
} |
|||
} |
|||
@ -1,67 +0,0 @@ |
|||
# LINGYUN.Abp.Identity.AspNetCore.Session |
|||
|
|||
User session login extension module, mainly handling login/logout events provided by *AspNetCore.Identity* to manage sessions. |
|||
|
|||
Due to module responsibility separation principle, please do not confuse with *LINGYUN.Abp.Identity.Session.AspNetCore* module. |
|||
|
|||
## Configuration Usage |
|||
|
|||
```csharp |
|||
[DependsOn(typeof(AbpIdentityAspNetCoreSessionModule))] |
|||
public class YouProjectModule : AbpModule |
|||
{ |
|||
// other |
|||
} |
|||
``` |
|||
|
|||
## Features |
|||
|
|||
* Extends AbpIdentityAspNetCoreModule module |
|||
* Provides session management functionality in AspNetCore environment |
|||
* Custom authentication service implementation |
|||
* Integrates with AspNetCore.Identity login/logout events |
|||
|
|||
## Service Implementation |
|||
|
|||
* AbpIdentitySessionAuthenticationService - Custom authentication service |
|||
* Handles user login/logout events |
|||
* Manages user session state |
|||
* Integrates with Identity session system |
|||
|
|||
## Basic Usage |
|||
|
|||
1. Configure authentication service |
|||
```csharp |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
context.Services.AddTransient<IAuthenticationService, AbpIdentitySessionAuthenticationService>(); |
|||
} |
|||
``` |
|||
|
|||
2. Use authentication service |
|||
```csharp |
|||
public class YourService |
|||
{ |
|||
private readonly IAuthenticationService _authenticationService; |
|||
|
|||
public YourService(IAuthenticationService authenticationService) |
|||
{ |
|||
_authenticationService = authenticationService; |
|||
} |
|||
|
|||
public async Task SignInAsync(HttpContext context, string scheme, ClaimsPrincipal principal, AuthenticationProperties properties) |
|||
{ |
|||
await _authenticationService.SignInAsync(context, scheme, principal, properties); |
|||
} |
|||
|
|||
public async Task SignOutAsync(HttpContext context, string scheme, AuthenticationProperties properties) |
|||
{ |
|||
await _authenticationService.SignOutAsync(context, scheme, properties); |
|||
} |
|||
} |
|||
``` |
|||
|
|||
## More Information |
|||
|
|||
* [ABP Identity Documentation](https://docs.abp.io/en/abp/latest/Identity) |
|||
* [ASP.NET Core Identity Documentation](https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity) |
|||
@ -1,67 +0,0 @@ |
|||
# LINGYUN.Abp.Identity.AspNetCore.Session |
|||
|
|||
用户会话登录扩展模块,主要处理 *AspNetCore.Identity* 提供的登录/登出事件来管理会话 |
|||
|
|||
出于模块职责分离原则, 请勿与 *LINGYUN.Abp.Identity.Session.AspNetCore* 模块混淆 |
|||
|
|||
## 配置使用 |
|||
|
|||
```csharp |
|||
[DependsOn(typeof(AbpIdentityAspNetCoreSessionModule))] |
|||
public class YouProjectModule : AbpModule |
|||
{ |
|||
// other |
|||
} |
|||
``` |
|||
|
|||
## 功能特性 |
|||
|
|||
* 扩展AbpIdentityAspNetCoreModule模块 |
|||
* 提供AspNetCore环境下的会话管理功能 |
|||
* 自定义身份认证服务实现 |
|||
* 集成AspNetCore.Identity的登录/登出事件 |
|||
|
|||
## 服务实现 |
|||
|
|||
* AbpIdentitySessionAuthenticationService - 自定义身份认证服务 |
|||
* 处理用户登录/登出事件 |
|||
* 管理用户会话状态 |
|||
* 与Identity会话系统集成 |
|||
|
|||
## 基本用法 |
|||
|
|||
1. 配置身份认证服务 |
|||
```csharp |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
context.Services.AddTransient<IAuthenticationService, AbpIdentitySessionAuthenticationService>(); |
|||
} |
|||
``` |
|||
|
|||
2. 使用身份认证服务 |
|||
```csharp |
|||
public class YourService |
|||
{ |
|||
private readonly IAuthenticationService _authenticationService; |
|||
|
|||
public YourService(IAuthenticationService authenticationService) |
|||
{ |
|||
_authenticationService = authenticationService; |
|||
} |
|||
|
|||
public async Task SignInAsync(HttpContext context, string scheme, ClaimsPrincipal principal, AuthenticationProperties properties) |
|||
{ |
|||
await _authenticationService.SignInAsync(context, scheme, principal, properties); |
|||
} |
|||
|
|||
public async Task SignOutAsync(HttpContext context, string scheme, AuthenticationProperties properties) |
|||
{ |
|||
await _authenticationService.SignOutAsync(context, scheme, properties); |
|||
} |
|||
} |
|||
``` |
|||
|
|||
## 更多信息 |
|||
|
|||
* [ABP身份认证文档](https://docs.abp.io/en/abp/latest/Identity) |
|||
* [ASP.NET Core Identity文档](https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity) |
|||
@ -1,38 +0,0 @@ |
|||
using System; |
|||
using System.Linq; |
|||
using System.Security.Claims; |
|||
using System.Security.Principal; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Security.Claims; |
|||
|
|||
namespace LINGYUN.Abp.Identity.Session.AspNetCore; |
|||
public class IdentitySessionClaimsPrincipalContributor : IAbpClaimsPrincipalContributor, ITransientDependency |
|||
{ |
|||
public virtual Task ContributeAsync(AbpClaimsPrincipalContributorContext context) |
|||
{ |
|||
var claimsIdentity = context.ClaimsPrincipal.Identities.First(); |
|||
if (claimsIdentity.HasClaim(x => x.Type == AbpClaimTypes.SessionId)) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
var sessionId = claimsIdentity.FindSessionId(); |
|||
if (!sessionId.IsNullOrWhiteSpace()) |
|||
{ |
|||
claimsIdentity.AddOrReplace(new Claim(AbpClaimTypes.SessionId, sessionId)); |
|||
context.ClaimsPrincipal.AddIdentityIfNotContains(claimsIdentity); |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
var userId = claimsIdentity.FindUserId(); |
|||
if (userId.HasValue) |
|||
{ |
|||
var sessionInfoProvider = context.GetRequiredService<ISessionInfoProvider>(); |
|||
sessionId = sessionInfoProvider.SessionId ?? Guid.NewGuid().ToString("N"); |
|||
|
|||
claimsIdentity.AddOrReplace(new Claim(AbpClaimTypes.SessionId, sessionId)); |
|||
context.ClaimsPrincipal.AddIdentityIfNotContains(claimsIdentity); |
|||
} |
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
@ -1,31 +0,0 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace LINGYUN.Abp.Identity.Session; |
|||
/// <summary>
|
|||
/// 用于会话管理的配置
|
|||
/// </summary>
|
|||
public class IdentitySessionSignInOptions |
|||
{ |
|||
/// <summary>
|
|||
/// 用于处理的身份认证方案
|
|||
/// </summary>
|
|||
public List<string> AuthenticationSchemes { get; set; } |
|||
/// <summary>
|
|||
/// 是否启用SignInManager登录会话
|
|||
/// 默认: false
|
|||
/// </summary>
|
|||
public bool SignInSessionEnabled { get; set; } |
|||
/// <summary>
|
|||
/// 是否启用SignInManager登出会话
|
|||
/// 默认: false
|
|||
/// </summary>
|
|||
public bool SignOutSessionEnabled { get; set; } |
|||
|
|||
public IdentitySessionSignInOptions() |
|||
{ |
|||
AuthenticationSchemes = new List<string> |
|||
{ |
|||
"Identity.Application" |
|||
}; |
|||
} |
|||
} |
|||
@ -1,3 +0,0 @@ |
|||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> |
|||
<ConfigureAwait ContinueOnCapturedContext="false" /> |
|||
</Weavers> |
|||
@ -1,30 +0,0 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
|||
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. --> |
|||
<xs:element name="Weavers"> |
|||
<xs:complexType> |
|||
<xs:all> |
|||
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1"> |
|||
<xs:complexType> |
|||
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" /> |
|||
</xs:complexType> |
|||
</xs:element> |
|||
</xs:all> |
|||
<xs:attribute name="VerifyAssembly" type="xs:boolean"> |
|||
<xs:annotation> |
|||
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation> |
|||
</xs:annotation> |
|||
</xs:attribute> |
|||
<xs:attribute name="VerifyIgnoreCodes" type="xs:string"> |
|||
<xs:annotation> |
|||
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation> |
|||
</xs:annotation> |
|||
</xs:attribute> |
|||
<xs:attribute name="GenerateXsd" type="xs:boolean"> |
|||
<xs:annotation> |
|||
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation> |
|||
</xs:annotation> |
|||
</xs:attribute> |
|||
</xs:complexType> |
|||
</xs:element> |
|||
</xs:schema> |
|||
@ -1,12 +0,0 @@ |
|||
using LINGYUN.Abp.IP.Location; |
|||
using Volo.Abp.AspNetCore; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace LINGYUN.Abp.Identity.Session.AspNetCore; |
|||
|
|||
[DependsOn(typeof(AbpAspNetCoreModule))] |
|||
[DependsOn(typeof(AbpIPLocationModule))] |
|||
[DependsOn(typeof(AbpIdentitySessionModule))] |
|||
public class AbpIdentitySessionAspNetCoreModule : AbpModule |
|||
{ |
|||
} |
|||
@ -1,22 +0,0 @@ |
|||
using Microsoft.AspNetCore.Builder; |
|||
|
|||
namespace LINGYUN.Abp.Identity.Session.AspNetCore; |
|||
public static class AbpSessionApplicationBuilderExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// 会话管理中间件
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// 建议顺序:<br />
|
|||
/// <seealso cref="AuthAppBuilderExtensions.UseAuthentication(IApplicationBuilder)"/><br />
|
|||
/// <seealso cref="AbpSessionApplicationBuilderExtensions.UseAbpSession(IApplicationBuilder)"/><br />
|
|||
/// <seealso cref="AbpApplicationBuilderExtensions.UseDynamicClaims(IApplicationBuilder)"/><br />
|
|||
/// <seealso cref="AuthorizationAppBuilderExtensions.UseAuthorization(IApplicationBuilder)"/><br />
|
|||
/// </remarks>
|
|||
/// <param name="app"></param>
|
|||
/// <returns></returns>
|
|||
public static IApplicationBuilder UseAbpSession(this IApplicationBuilder app) |
|||
{ |
|||
return app.UseMiddleware<AbpSessionMiddleware>(); |
|||
} |
|||
} |
|||
@ -1,42 +0,0 @@ |
|||
using Microsoft.AspNetCore.Http; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Options; |
|||
using System; |
|||
using System.Security.Principal; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.AspNetCore.Middleware; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Security.Claims; |
|||
using Volo.Abp.Tracing; |
|||
|
|||
namespace LINGYUN.Abp.Identity.Session.AspNetCore; |
|||
public class AbpSessionMiddleware : AbpMiddlewareBase, ITransientDependency |
|||
{ |
|||
private readonly ISessionInfoProvider _sessionInfoProvider; |
|||
private readonly ICorrelationIdProvider _correlationIdProvider; |
|||
|
|||
public AbpSessionMiddleware( |
|||
ISessionInfoProvider sessionInfoProvider, |
|||
ICorrelationIdProvider correlationIdProvider) |
|||
{ |
|||
_sessionInfoProvider = sessionInfoProvider; |
|||
_correlationIdProvider = correlationIdProvider; |
|||
} |
|||
|
|||
public override Task InvokeAsync(HttpContext context, RequestDelegate next) |
|||
{ |
|||
var sessionId = _correlationIdProvider.Get() ?? Guid.NewGuid().ToString("N"); |
|||
if (context.User.Identity?.IsAuthenticated == true) |
|||
{ |
|||
if (context.RequestServices.GetRequiredService<IOptions<AbpClaimsPrincipalFactoryOptions>>().Value.IsDynamicClaimsEnabled) |
|||
{ |
|||
// 在处理动态声明前保留全局会话用于验证
|
|||
sessionId = context.User.FindSessionId(); |
|||
} |
|||
} |
|||
using (_sessionInfoProvider.Change(sessionId)) |
|||
{ |
|||
return next(context); |
|||
} |
|||
} |
|||
} |
|||
@ -1,97 +0,0 @@ |
|||
# LINGYUN.Abp.Identity.Session.AspNetCore |
|||
|
|||
Identity service user session extension module. |
|||
|
|||
## Interface Description |
|||
|
|||
### AbpSessionMiddleware extracts *sessionId* from user token in the request pipeline as a global session identifier, which can be used to log out sessions |
|||
> Note: When anonymous users access, the request *CorrelationId* is used as the identifier; |
|||
When *CorrelationId* does not exist, use random *Guid.NewGuid()*. |
|||
|
|||
### HttpContextDeviceInfoProvider extracts device identification from request parameters |
|||
|
|||
> Due to module responsibility separation principle, please do not confuse with *LINGYUN.Abp.Identity.AspNetCore.Session* module |
|||
|
|||
### HttpContextDeviceInfoProvider is used to handle session IP address location parsing |
|||
|
|||
> IsParseIpLocation will parse the geographical location of session IP when enabled |
|||
> IgnoreProvinces are provinces that need to be ignored when parsing geographical locations, usually China's municipalities |
|||
> LocationParser customizes the geographical location data that needs to be processed |
|||
|
|||
## Features |
|||
|
|||
* Provides session management functionality in AspNetCore environment |
|||
* Supports extracting device identification information from requests |
|||
* Supports IP geolocation parsing |
|||
* Depends on AbpAspNetCoreModule, AbpIP2RegionModule, and AbpIdentitySessionModule |
|||
|
|||
## Configuration Options |
|||
|
|||
### AbpIdentitySessionAspNetCoreOptions |
|||
|
|||
```json |
|||
{ |
|||
"Identity": { |
|||
"Session": { |
|||
"AspNetCore": { |
|||
"IsParseIpLocation": false, // Whether to parse IP geographic information, default: false |
|||
"IgnoreProvinces": [ // Provinces to ignore, default includes China's municipalities |
|||
"Beijing", |
|||
"Shanghai", |
|||
"Tianjin", |
|||
"Chongqing" |
|||
] |
|||
} |
|||
} |
|||
} |
|||
} |
|||
``` |
|||
|
|||
## Basic Usage |
|||
|
|||
1. Configure IP geolocation parsing |
|||
```csharp |
|||
Configure<AbpIdentitySessionAspNetCoreOptions>(options => |
|||
{ |
|||
options.IsParseIpLocation = true; // Enable IP geolocation parsing |
|||
options.IgnoreProvinces.Add("Hong Kong"); // Add provinces to ignore |
|||
options.LocationParser = (locationInfo) => |
|||
{ |
|||
// Custom geolocation parsing logic |
|||
return $"{locationInfo.Country}{locationInfo.Province}{locationInfo.City}"; |
|||
}; |
|||
}); |
|||
``` |
|||
|
|||
2. Use device information provider |
|||
```csharp |
|||
public class YourService |
|||
{ |
|||
private readonly IDeviceInfoProvider _deviceInfoProvider; |
|||
|
|||
public YourService(IDeviceInfoProvider deviceInfoProvider) |
|||
{ |
|||
_deviceInfoProvider = deviceInfoProvider; |
|||
} |
|||
|
|||
public async Task<DeviceInfo> GetDeviceInfoAsync() |
|||
{ |
|||
return await _deviceInfoProvider.GetDeviceInfoAsync(); |
|||
} |
|||
} |
|||
``` |
|||
|
|||
## Configuration Usage |
|||
|
|||
```csharp |
|||
[DependsOn(typeof(AbpIdentitySessionAspNetCoreModule))] |
|||
public class YouProjectModule : AbpModule |
|||
{ |
|||
// other |
|||
} |
|||
``` |
|||
|
|||
## More Information |
|||
|
|||
* [ABP Identity Documentation](https://docs.abp.io/en/abp/latest/Identity) |
|||
* [ABP AspNetCore Documentation](https://docs.abp.io/en/abp/latest/AspNetCore) |
|||
@ -1,98 +0,0 @@ |
|||
# LINGYUN.Abp.Identity.Session.AspNetCore |
|||
|
|||
身份服务用户会话扩展模块 |
|||
|
|||
## 接口描述 |
|||
|
|||
### AbpSessionMiddleware 在请求管道中从用户令牌提取 *sessionId* 作为全局会话标识, 可用于注销会话 |
|||
> 注意: 当匿名用户访问时, 以请求 *CorrelationId* 作为标识; |
|||
当 *CorrelationId* 不存在时, 使用随机 *Guid.NewGuid()*. |
|||
|
|||
### HttpContextDeviceInfoProvider 从请求参数中提取设备标识 |
|||
|
|||
> 出于模块职责分离原则, 请勿与 *LINGYUN.Abp.Identity.AspNetCore.Session* 模块混淆 |
|||
|
|||
|
|||
### HttpContextDeviceInfoProvider 用于处理会话IP的地址位置解析 |
|||
|
|||
> IsParseIpLocation 启用后将对会话IP进行地理位置解析 |
|||
> IgnoreProvinces 解析地理位置时需要忽略的省份,通常情况下中国的直辖市需要 |
|||
> LocationParser 自定义需要处理的地理位置数据 |
|||
|
|||
## 功能特性 |
|||
|
|||
* 提供AspNetCore环境下的会话管理功能 |
|||
* 支持从请求中提取设备标识信息 |
|||
* 支持IP地理位置解析功能 |
|||
* 依赖AbpAspNetCoreModule、AbpIP2RegionModule和AbpIdentitySessionModule模块 |
|||
|
|||
## 配置项 |
|||
|
|||
### AbpIdentitySessionAspNetCoreOptions |
|||
|
|||
```json |
|||
{ |
|||
"Identity": { |
|||
"Session": { |
|||
"AspNetCore": { |
|||
"IsParseIpLocation": false, // 是否解析IP地理信息,默认:false |
|||
"IgnoreProvinces": [ // 不做处理的省份,默认包含中国直辖市 |
|||
"北京", |
|||
"上海", |
|||
"天津", |
|||
"重庆" |
|||
] |
|||
} |
|||
} |
|||
} |
|||
} |
|||
``` |
|||
|
|||
## 基本用法 |
|||
|
|||
1. 配置IP地理位置解析 |
|||
```csharp |
|||
Configure<AbpIdentitySessionAspNetCoreOptions>(options => |
|||
{ |
|||
options.IsParseIpLocation = true; // 启用IP地理位置解析 |
|||
options.IgnoreProvinces.Add("香港"); // 添加需要忽略的省份 |
|||
options.LocationParser = (locationInfo) => |
|||
{ |
|||
// 自定义地理位置解析逻辑 |
|||
return $"{locationInfo.Country}{locationInfo.Province}{locationInfo.City}"; |
|||
}; |
|||
}); |
|||
``` |
|||
|
|||
2. 使用设备信息提供者 |
|||
```csharp |
|||
public class YourService |
|||
{ |
|||
private readonly IDeviceInfoProvider _deviceInfoProvider; |
|||
|
|||
public YourService(IDeviceInfoProvider deviceInfoProvider) |
|||
{ |
|||
_deviceInfoProvider = deviceInfoProvider; |
|||
} |
|||
|
|||
public async Task<DeviceInfo> GetDeviceInfoAsync() |
|||
{ |
|||
return await _deviceInfoProvider.GetDeviceInfoAsync(); |
|||
} |
|||
} |
|||
``` |
|||
|
|||
## 配置使用 |
|||
|
|||
```csharp |
|||
[DependsOn(typeof(AbpIdentitySessionAspNetCoreModule))] |
|||
public class YouProjectModule : AbpModule |
|||
{ |
|||
// other |
|||
} |
|||
``` |
|||
|
|||
## 更多信息 |
|||
|
|||
* [ABP身份认证文档](https://docs.abp.io/en/abp/latest/Identity) |
|||
* [ABP AspNetCore文档](https://docs.abp.io/en/abp/latest/AspNetCore) |
|||
@ -1,3 +0,0 @@ |
|||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> |
|||
<ConfigureAwait ContinueOnCapturedContext="false" /> |
|||
</Weavers> |
|||
@ -1,30 +0,0 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
|||
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. --> |
|||
<xs:element name="Weavers"> |
|||
<xs:complexType> |
|||
<xs:all> |
|||
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1"> |
|||
<xs:complexType> |
|||
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" /> |
|||
</xs:complexType> |
|||
</xs:element> |
|||
</xs:all> |
|||
<xs:attribute name="VerifyAssembly" type="xs:boolean"> |
|||
<xs:annotation> |
|||
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation> |
|||
</xs:annotation> |
|||
</xs:attribute> |
|||
<xs:attribute name="VerifyIgnoreCodes" type="xs:string"> |
|||
<xs:annotation> |
|||
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation> |
|||
</xs:annotation> |
|||
</xs:attribute> |
|||
<xs:attribute name="GenerateXsd" type="xs:boolean"> |
|||
<xs:annotation> |
|||
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation> |
|||
</xs:annotation> |
|||
</xs:attribute> |
|||
</xs:complexType> |
|||
</xs:element> |
|||
</xs:schema> |
|||
@ -1,22 +0,0 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\..\..\configureawait.props" /> |
|||
<Import Project="..\..\..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>net10.0</TargetFramework> |
|||
<AssemblyName>LINGYUN.Abp.IdentityServer.Session</AssemblyName> |
|||
<PackageId>LINGYUN.Abp.IdentityServer.Session</PackageId> |
|||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
|||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
|||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\identity\LINGYUN.Abp.Identity.Domain\LINGYUN.Abp.Identity.Domain.csproj" /> |
|||
<ProjectReference Include="..\..\identity\LINGYUN.Abp.Identity.Session\LINGYUN.Abp.Identity.Session.csproj" /> |
|||
<ProjectReference Include="..\LINGYUN.Abp.IdentityServer.Domain\LINGYUN.Abp.IdentityServer.Domain.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -1,42 +0,0 @@ |
|||
using IdentityServer4.Validation; |
|||
using LINGYUN.Abp.Identity; |
|||
using LINGYUN.Abp.Identity.Session; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.DependencyInjection.Extensions; |
|||
using Volo.Abp.IdentityServer; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.Security.Claims; |
|||
|
|||
namespace LINGYUN.Abp.IdentityServer.Session; |
|||
|
|||
[DependsOn( |
|||
typeof(AbpIdentityServerDomainModule), |
|||
typeof(AbpIdentityDomainModule), |
|||
typeof(AbpIdentitySessionModule))] |
|||
public class AbpIdentityServerSessionModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
Configure<AbpIdentityServerEventOptions>(options => |
|||
{ |
|||
options.EventServiceHandlers.Add<AbpIdentitySessionEventServiceHandler>(); |
|||
}); |
|||
|
|||
Configure<AbpClaimsServiceOptions>(options => |
|||
{ |
|||
options.RequestedClaims.Add(AbpClaimTypes.SessionId); |
|||
}); |
|||
|
|||
Configure<IdentitySessionSignInOptions>(options => |
|||
{ |
|||
// UserLoginSuccessEvent由IdentityServer发布, 无需显式保存会话
|
|||
options.SignInSessionEnabled = false; |
|||
// UserLoginSuccessEvent由用户发布, 需要显式注销会话
|
|||
options.SignOutSessionEnabled = true; |
|||
}); |
|||
|
|||
// 默认UserinfoEndpoint仅解密token
|
|||
// 启用此模块需要验证会话有效性
|
|||
context.Services.Replace(ServiceDescriptor.Transient<IUserInfoRequestValidator, AbpIdentitySessionUserInfoRequestValidator>()); |
|||
} |
|||
} |
|||
@ -1,102 +0,0 @@ |
|||
using IdentityServer4.Events; |
|||
using LINGYUN.Abp.Identity.Session; |
|||
using System; |
|||
using System.Security.Claims; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.MultiTenancy; |
|||
using Volo.Abp.Security.Claims; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace LINGYUN.Abp.IdentityServer.Session; |
|||
/// <summary>
|
|||
/// 持久化用户会话
|
|||
/// </summary>
|
|||
public class AbpIdentitySessionEventServiceHandler : IAbpIdentityServerEventServiceHandler, ITransientDependency |
|||
{ |
|||
protected ICurrentTenant CurrentTenant { get; } |
|||
protected ISessionInfoProvider SessionInfoProvider { get; } |
|||
protected IIdentitySessionManager IdentitySessionManager { get; } |
|||
protected ICurrentPrincipalAccessor CurrentPrincipalAccessor { get; } |
|||
|
|||
public AbpIdentitySessionEventServiceHandler( |
|||
ICurrentTenant currentTenant, |
|||
ISessionInfoProvider sessionInfoProvider, |
|||
IIdentitySessionManager identitySessionManager, |
|||
ICurrentPrincipalAccessor currentPrincipalAccessor) |
|||
{ |
|||
CurrentTenant = currentTenant; |
|||
SessionInfoProvider = sessionInfoProvider; |
|||
IdentitySessionManager = identitySessionManager; |
|||
CurrentPrincipalAccessor = currentPrincipalAccessor; |
|||
} |
|||
|
|||
public virtual bool CanRaiseEventType(EventTypes evtType) |
|||
{ |
|||
return evtType == EventTypes.Success; |
|||
} |
|||
|
|||
[UnitOfWork] |
|||
public virtual Task RaiseAsync(Event evt) |
|||
{ |
|||
if (evt is UserLoginSuccessEvent loginEvent) |
|||
{ |
|||
// 用户登录事件
|
|||
return RaiseUserLoginSuccessEventAsync(loginEvent); |
|||
} |
|||
if (evt is UserLogoutSuccessEvent logoutEvent) |
|||
{ |
|||
// 用户退出事件
|
|||
return RaiseUserLogoutSuccessEventAsync(logoutEvent); |
|||
} |
|||
if (evt is TokenRevokedSuccessEvent revokeEvent) |
|||
{ |
|||
// 撤销令牌事件
|
|||
return RaiseTokenRevokedSuccessEventAsync(revokeEvent); |
|||
} |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
protected async virtual Task RaiseUserLoginSuccessEventAsync(UserLoginSuccessEvent loginEvent) |
|||
{ |
|||
var subjectId = loginEvent.SubjectId; |
|||
var sessionId = SessionInfoProvider.SessionId; |
|||
if (!sessionId.IsNullOrWhiteSpace() && |
|||
Guid.TryParse(subjectId, out var userId)) |
|||
{ |
|||
var claimsIdentity = new ClaimsIdentity(); |
|||
claimsIdentity.AddClaim(new Claim(AbpClaimTypes.UserId, userId.ToString())); |
|||
claimsIdentity.AddClaim(new Claim(AbpClaimTypes.SessionId, sessionId)); |
|||
if (!loginEvent.ClientId.IsNullOrWhiteSpace()) |
|||
{ |
|||
claimsIdentity.AddClaim(new Claim(AbpClaimTypes.ClientId, loginEvent.ClientId)); |
|||
} |
|||
if (CurrentTenant.IsAvailable) |
|||
{ |
|||
claimsIdentity.AddClaim(new Claim(AbpClaimTypes.TenantId, CurrentTenant.Id!.Value.ToString())); |
|||
} |
|||
var claimsPrincipal = new ClaimsPrincipal(claimsIdentity); |
|||
using (CurrentPrincipalAccessor.Change(claimsPrincipal)) |
|||
{ |
|||
await IdentitySessionManager.SaveSessionAsync(claimsPrincipal); |
|||
} |
|||
} |
|||
} |
|||
protected async virtual Task RaiseUserLogoutSuccessEventAsync(UserLogoutSuccessEvent logoutEvent) |
|||
{ |
|||
var sessionId = SessionInfoProvider.SessionId; |
|||
if (!sessionId.IsNullOrWhiteSpace()) |
|||
{ |
|||
await IdentitySessionManager.RevokeSessionAsync(sessionId); |
|||
} |
|||
} |
|||
|
|||
protected async virtual Task RaiseTokenRevokedSuccessEventAsync(TokenRevokedSuccessEvent revokeEvent) |
|||
{ |
|||
var sessionId = SessionInfoProvider.SessionId; |
|||
if (!sessionId.IsNullOrWhiteSpace()) |
|||
{ |
|||
await IdentitySessionManager.RevokeSessionAsync(sessionId); |
|||
} |
|||
} |
|||
} |
|||
@ -1,77 +0,0 @@ |
|||
# LINGYUN.Abp.IdentityServer.Session |
|||
|
|||
IdentityServer session management module that provides user session management and validation functionality. |
|||
|
|||
## Features |
|||
|
|||
* Session Validation |
|||
* `AbpIdentitySessionUserInfoRequestValidator` - User Info Request Validator |
|||
* Validates user session status |
|||
* Validates access token validity |
|||
* Validates user active status |
|||
* Supports OpenID Connect standard |
|||
|
|||
* Session Event Handling |
|||
* `AbpIdentitySessionEventServiceHandler` - Session Event Handler |
|||
* Handles user login success events |
|||
* Saves session information |
|||
* Supports multi-tenancy |
|||
* Records client identifier |
|||
* Handles user logout success events |
|||
* Revokes session |
|||
* Handles token revocation success events |
|||
* Revokes session |
|||
|
|||
* Configuration Options |
|||
* Session Claims Configuration |
|||
* Add SessionId claim |
|||
* Session Login Configuration |
|||
* Disable explicit session saving |
|||
* Enable explicit session logout |
|||
|
|||
## Module Reference |
|||
|
|||
```csharp |
|||
[DependsOn( |
|||
typeof(AbpIdentityServerSessionModule) |
|||
)] |
|||
public class YourModule : AbpModule |
|||
{ |
|||
// ... |
|||
} |
|||
``` |
|||
|
|||
## Dependencies |
|||
|
|||
* `AbpIdentityServerDomainModule` - ABP IdentityServer Domain Module |
|||
* `AbpIdentityDomainModule` - ABP Identity Domain Module |
|||
* `AbpIdentitySessionModule` - ABP Identity Session Module |
|||
|
|||
## Configuration and Usage |
|||
|
|||
### Configure Session Options |
|||
|
|||
```csharp |
|||
Configure<IdentitySessionSignInOptions>(options => |
|||
{ |
|||
// UserLoginSuccessEvent is published by IdentityServer, no need for explicit session saving |
|||
options.SignInSessionEnabled = false; |
|||
// UserLoginSuccessEvent is published by user, requires explicit session logout |
|||
options.SignOutSessionEnabled = true; |
|||
}); |
|||
``` |
|||
|
|||
### Configure Claims Options |
|||
|
|||
```csharp |
|||
Configure<AbpClaimsServiceOptions>(options => |
|||
{ |
|||
options.RequestedClaims.Add(AbpClaimTypes.SessionId); |
|||
}); |
|||
``` |
|||
|
|||
Related Documentation: |
|||
* [IdentityServer4 Documentation](https://identityserver4.readthedocs.io/) |
|||
* [ABP Identity Documentation](https://docs.abp.io/en/abp/latest/Modules/Identity) |
|||
|
|||
[查看中文文档](README.md) |
|||
@ -1,77 +0,0 @@ |
|||
# LINGYUN.Abp.IdentityServer.Session |
|||
|
|||
IdentityServer会话管理模块,提供用户会话管理和验证功能。 |
|||
|
|||
## 功能特性 |
|||
|
|||
* 会话验证 |
|||
* `AbpIdentitySessionUserInfoRequestValidator` - 用户信息请求验证器 |
|||
* 验证用户会话状态 |
|||
* 验证访问令牌有效性 |
|||
* 验证用户活动状态 |
|||
* 支持OpenID Connect标准 |
|||
|
|||
* 会话事件处理 |
|||
* `AbpIdentitySessionEventServiceHandler` - 会话事件处理器 |
|||
* 处理用户登录成功事件 |
|||
* 保存会话信息 |
|||
* 支持多租户 |
|||
* 记录客户端标识 |
|||
* 处理用户登出成功事件 |
|||
* 撤销会话 |
|||
* 处理令牌撤销成功事件 |
|||
* 撤销会话 |
|||
|
|||
* 配置选项 |
|||
* 会话声明配置 |
|||
* 添加SessionId声明 |
|||
* 会话登录配置 |
|||
* 禁用显式保存会话 |
|||
* 启用显式注销会话 |
|||
|
|||
## 模块引用 |
|||
|
|||
```csharp |
|||
[DependsOn( |
|||
typeof(AbpIdentityServerSessionModule) |
|||
)] |
|||
public class YourModule : AbpModule |
|||
{ |
|||
// ... |
|||
} |
|||
``` |
|||
|
|||
## 依赖模块 |
|||
|
|||
* `AbpIdentityServerDomainModule` - ABP IdentityServer领域模块 |
|||
* `AbpIdentityDomainModule` - ABP Identity领域模块 |
|||
* `AbpIdentitySessionModule` - ABP Identity会话模块 |
|||
|
|||
## 配置使用 |
|||
|
|||
### 配置会话选项 |
|||
|
|||
```csharp |
|||
Configure<IdentitySessionSignInOptions>(options => |
|||
{ |
|||
// UserLoginSuccessEvent由IdentityServer发布, 无需显式保存会话 |
|||
options.SignInSessionEnabled = false; |
|||
// UserLoginSuccessEvent由用户发布, 需要显式注销会话 |
|||
options.SignOutSessionEnabled = true; |
|||
}); |
|||
``` |
|||
|
|||
### 配置声明选项 |
|||
|
|||
```csharp |
|||
Configure<AbpClaimsServiceOptions>(options => |
|||
{ |
|||
options.RequestedClaims.Add(AbpClaimTypes.SessionId); |
|||
}); |
|||
``` |
|||
|
|||
相关文档: |
|||
* [IdentityServer4文档](https://identityserver4.readthedocs.io/) |
|||
* [ABP Identity文档](https://docs.abp.io/en/abp/latest/Modules/Identity) |
|||
|
|||
[查看英文文档](README.EN.md) |
|||
@ -1,3 +0,0 @@ |
|||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> |
|||
<ConfigureAwait ContinueOnCapturedContext="false" /> |
|||
</Weavers> |
|||
@ -1,30 +0,0 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
|||
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. --> |
|||
<xs:element name="Weavers"> |
|||
<xs:complexType> |
|||
<xs:all> |
|||
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1"> |
|||
<xs:complexType> |
|||
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" /> |
|||
</xs:complexType> |
|||
</xs:element> |
|||
</xs:all> |
|||
<xs:attribute name="VerifyAssembly" type="xs:boolean"> |
|||
<xs:annotation> |
|||
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation> |
|||
</xs:annotation> |
|||
</xs:attribute> |
|||
<xs:attribute name="VerifyIgnoreCodes" type="xs:string"> |
|||
<xs:annotation> |
|||
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation> |
|||
</xs:annotation> |
|||
</xs:attribute> |
|||
<xs:attribute name="GenerateXsd" type="xs:boolean"> |
|||
<xs:annotation> |
|||
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation> |
|||
</xs:annotation> |
|||
</xs:attribute> |
|||
</xs:complexType> |
|||
</xs:element> |
|||
</xs:schema> |
|||
@ -1,25 +0,0 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\..\..\configureawait.props" /> |
|||
<Import Project="..\..\..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>net10.0</TargetFramework> |
|||
<AssemblyName>LINGYUN.Abp.OpenIddict.AspNetCore.Session</AssemblyName> |
|||
<PackageId>LINGYUN.Abp.OpenIddict.AspNetCore.Session</PackageId> |
|||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
|||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
|||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Volo.Abp.OpenIddict.AspNetCore" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\identity\LINGYUN.Abp.Identity.Domain\LINGYUN.Abp.Identity.Domain.csproj" /> |
|||
<ProjectReference Include="..\..\identity\LINGYUN.Abp.Identity.Session.AspNetCore\LINGYUN.Abp.Identity.Session.AspNetCore.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -1,54 +0,0 @@ |
|||
using LINGYUN.Abp.Identity; |
|||
using LINGYUN.Abp.Identity.Session; |
|||
using LINGYUN.Abp.Identity.Session.AspNetCore; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using OpenIddict.Server; |
|||
using OpenIddict.Validation; |
|||
using Volo.Abp.Modularity; |
|||
using static OpenIddict.Abstractions.OpenIddictConstants; |
|||
|
|||
namespace LINGYUN.Abp.OpenIddict.AspNetCore.Session; |
|||
|
|||
[DependsOn( |
|||
typeof(AbpIdentityDomainModule), |
|||
typeof(AbpIdentitySessionAspNetCoreModule) |
|||
)] |
|||
public class AbpOpenIddictAspNetCoreSessionModule : AbpModule |
|||
{ |
|||
public override void PreConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
PreConfigure<OpenIddictServerBuilder>(builder => |
|||
{ |
|||
builder.AddEventHandler(ProcessSignOutIdentitySession.Descriptor); |
|||
builder.AddEventHandler(ProcessSignInIdentitySession.Descriptor); |
|||
builder.AddEventHandler(RevocationIdentitySession.Descriptor); |
|||
builder.AddEventHandler(ServerValidationTokenCheckIdentitySession.Descriptor); |
|||
// builder.AddEventHandler(UserInfoIdentitySession.Descriptor);
|
|||
}); |
|||
} |
|||
|
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
Configure<IdentitySessionSignInOptions>(options => |
|||
{ |
|||
options.SignInSessionEnabled = true; |
|||
options.SignOutSessionEnabled = true; |
|||
}); |
|||
|
|||
Configure<AbpOpenIddictAspNetCoreSessionOptions>(options => |
|||
{ |
|||
options.PersistentSessionGrantTypes.Add(GrantTypes.Password); |
|||
options.ValidationSessionEndpointTypes.Add(OpenIddictServerEndpointType.Token); |
|||
options.ValidationSessionEndpointTypes.Add(OpenIddictServerEndpointType.UserInfo); |
|||
options.ValidationSessionEndpointTypes.Add(OpenIddictServerEndpointType.Introspection); |
|||
options.ValidationSessionEndpointTypes.Add(OpenIddictServerEndpointType.Revocation); |
|||
}); |
|||
|
|||
context.Services.Add(ValidationTokenCheckIdentitySession.Descriptor.ServiceDescriptor); |
|||
|
|||
Configure<OpenIddictValidationOptions>(options => |
|||
{ |
|||
options.Handlers.Add(ValidationTokenCheckIdentitySession.Descriptor); |
|||
}); |
|||
} |
|||
} |
|||
@ -1,14 +0,0 @@ |
|||
using OpenIddict.Server; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace LINGYUN.Abp.OpenIddict.AspNetCore.Session; |
|||
public class AbpOpenIddictAspNetCoreSessionOptions |
|||
{ |
|||
public List<string> PersistentSessionGrantTypes { get; set; } |
|||
public List<OpenIddictServerEndpointType> ValidationSessionEndpointTypes { get; set; } |
|||
public AbpOpenIddictAspNetCoreSessionOptions() |
|||
{ |
|||
PersistentSessionGrantTypes = new List<string>(); |
|||
ValidationSessionEndpointTypes = new List<OpenIddictServerEndpointType>(); |
|||
} |
|||
} |
|||
@ -1,56 +0,0 @@ |
|||
using LINGYUN.Abp.Identity.Session; |
|||
using Microsoft.Extensions.Logging; |
|||
using Microsoft.Extensions.Logging.Abstractions; |
|||
using Microsoft.Extensions.Options; |
|||
using OpenIddict.Server; |
|||
using System; |
|||
using System.Security.Principal; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.OpenIddict.AspNetCore.Session; |
|||
/// <summary>
|
|||
/// 登录成功持久化用户会话
|
|||
/// </summary>
|
|||
public class ProcessSignInIdentitySession : IOpenIddictServerHandler<OpenIddictServerEvents.ProcessSignInContext> |
|||
{ |
|||
public ILogger<ProcessSignInIdentitySession> Logger { protected get; set; } |
|||
|
|||
protected IIdentitySessionManager IdentitySessionManager { get; } |
|||
protected AbpOpenIddictAspNetCoreSessionOptions AbpOpenIddictAspNetCoreSessionOptions { get; } |
|||
|
|||
public static OpenIddictServerHandlerDescriptor Descriptor { get; } |
|||
= OpenIddictServerHandlerDescriptor.CreateBuilder<OpenIddictServerEvents.ProcessSignInContext>() |
|||
.AddFilter<OpenIddictServerHandlerFilters.RequireAccessTokenGenerated>() |
|||
.UseScopedHandler<ProcessSignInIdentitySession>() |
|||
.SetOrder(OpenIddictServerHandlers.PrepareAccessTokenPrincipal.Descriptor.Order + 1_000) |
|||
.SetType(OpenIddictServerHandlerType.Custom) |
|||
.Build(); |
|||
|
|||
public ProcessSignInIdentitySession( |
|||
IIdentitySessionManager identitySessionManager, |
|||
IOptions<AbpOpenIddictAspNetCoreSessionOptions> abpOpenIddictAspNetCoreSessionOptions) |
|||
{ |
|||
IdentitySessionManager = identitySessionManager; |
|||
AbpOpenIddictAspNetCoreSessionOptions = abpOpenIddictAspNetCoreSessionOptions.Value; |
|||
|
|||
Logger = NullLogger<ProcessSignInIdentitySession>.Instance; |
|||
} |
|||
|
|||
public async virtual ValueTask HandleAsync(OpenIddictServerEvents.ProcessSignInContext context) |
|||
{ |
|||
if (!context.Request.GrantType.IsNullOrWhiteSpace() && |
|||
AbpOpenIddictAspNetCoreSessionOptions.PersistentSessionGrantTypes.Contains(context.Request.GrantType) && |
|||
context.Principal != null) |
|||
{ |
|||
Logger.LogInformation("Saving session for grant type: {grantType}", context.Request.GrantType); |
|||
|
|||
await IdentitySessionManager.SaveSessionAsync(context.Principal, context.CancellationToken); |
|||
|
|||
Logger.LogInformation("Session saved successfully: {sessionId}", context.Principal.FindSessionId()); |
|||
} |
|||
else |
|||
{ |
|||
Logger.LogDebug("Skipping session save for grant type: {grantType}", context.Request.GrantType); |
|||
} |
|||
} |
|||
} |
|||
@ -1,49 +0,0 @@ |
|||
using LINGYUN.Abp.Identity.Session; |
|||
using OpenIddict.Server; |
|||
using System; |
|||
using System.Security.Principal; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.MultiTenancy; |
|||
using static OpenIddict.Abstractions.OpenIddictConstants; |
|||
using static OpenIddict.Server.OpenIddictServerHandlers.UserInfo; |
|||
|
|||
namespace LINGYUN.Abp.OpenIddict.AspNetCore.Session; |
|||
/// <summary>
|
|||
/// UserInfoEndpoint 检查用户会话
|
|||
/// </summary>
|
|||
[Obsolete("UserInfoIdentitySession is outdated, please use the CheckIdentitySessionOnServerValidationToken")] |
|||
public class UserInfoIdentitySession : IOpenIddictServerHandler<OpenIddictServerEvents.HandleUserInfoRequestContext> |
|||
{ |
|||
protected ICurrentTenant CurrentTenant { get; } |
|||
protected IIdentitySessionChecker IdentitySessionChecker { get; } |
|||
|
|||
public static OpenIddictServerHandlerDescriptor Descriptor { get; } |
|||
= OpenIddictServerHandlerDescriptor.CreateBuilder<OpenIddictServerEvents.HandleUserInfoRequestContext>() |
|||
.AddFilter<OpenIddictServerHandlerFilters.RequireUserInfoRequest>() |
|||
.UseScopedHandler<UserInfoIdentitySession>() |
|||
.SetOrder(ValidateUserInfoRequest.Descriptor.Order + 2_000) |
|||
.SetType(OpenIddictServerHandlerType.Custom) |
|||
.Build(); |
|||
|
|||
public UserInfoIdentitySession( |
|||
ICurrentTenant currentTenant, |
|||
IIdentitySessionChecker identitySessionChecker) |
|||
{ |
|||
CurrentTenant = currentTenant; |
|||
IdentitySessionChecker = identitySessionChecker; |
|||
} |
|||
|
|||
public async virtual ValueTask HandleAsync(OpenIddictServerEvents.HandleUserInfoRequestContext context) |
|||
{ |
|||
var tenantId = context.AccessTokenPrincipal.FindTenantId(); |
|||
using (CurrentTenant.Change(tenantId)) |
|||
{ |
|||
if (!await IdentitySessionChecker.ValidateSessionAsync(context.AccessTokenPrincipal)) |
|||
{ |
|||
// Errors.InvalidToken ---> 401
|
|||
// Errors.ExpiredToken ---> 400
|
|||
context.Reject(Errors.InvalidToken, "The user session has expired."); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,76 +0,0 @@ |
|||
# LINGYUN.Abp.OpenIddict.AspNetCore.Session |
|||
|
|||
[](https://abp.io) |
|||
[](https://www.nuget.org/packages/LINGYUN.Abp.OpenIddict.AspNetCore.Session) |
|||
|
|||
## Introduction |
|||
|
|||
`LINGYUN.Abp.OpenIddict.AspNetCore.Session` is a session management extension module for OpenIddict, providing functionality for user session persistence, validation, and revocation. |
|||
|
|||
[简体中文](./README.md) |
|||
|
|||
## Features |
|||
|
|||
* User Session Management |
|||
* Automatic session persistence on login |
|||
* Automatic session termination on logout |
|||
* Automatic session termination on token revocation |
|||
* UserInfo endpoint session validation |
|||
|
|||
* Multi-tenancy Support |
|||
* Session management supports multi-tenant scenarios |
|||
* Tenant-isolated session storage |
|||
|
|||
* Configurable Session Persistence |
|||
* Support for configuring grant types that require session persistence |
|||
* Default support for password grant type |
|||
|
|||
## Installation |
|||
|
|||
```bash |
|||
dotnet add package LINGYUN.Abp.OpenIddict.AspNetCore.Session |
|||
``` |
|||
|
|||
## Usage |
|||
|
|||
1. Add `[DependsOn(typeof(AbpOpenIddictAspNetCoreSessionModule))]` to your module class. |
|||
|
|||
2. Configure session options: |
|||
|
|||
```csharp |
|||
Configure<IdentitySessionSignInOptions>(options => |
|||
{ |
|||
options.SignInSessionEnabled = true; // Enable login session |
|||
options.SignOutSessionEnabled = true; // Enable logout session |
|||
}); |
|||
|
|||
Configure<AbpOpenIddictAspNetCoreSessionOptions>(options => |
|||
{ |
|||
// Configure grant types that require session persistence |
|||
options.PersistentSessionGrantTypes.Add(GrantTypes.Password); |
|||
options.PersistentSessionGrantTypes.Add("custom_grant_type"); |
|||
}); |
|||
``` |
|||
|
|||
## Workflow |
|||
|
|||
1. User Login |
|||
* When a user successfully logs in through configured grant types |
|||
* System automatically creates and persists session information |
|||
|
|||
2. Session Validation |
|||
* When user accesses the UserInfo endpoint |
|||
* System automatically validates if the session is valid |
|||
* Returns appropriate error if session has expired or is invalid |
|||
|
|||
3. Session Termination |
|||
* Automatically terminates session on user logout |
|||
* Automatically terminates related sessions on token revocation |
|||
* Supports session management for multiple concurrent logins |
|||
|
|||
## Notes |
|||
|
|||
* Session persistence only applies to configured grant types |
|||
* Session validation automatically switches tenant context in multi-tenant environments |
|||
* Token revocation will terminate related user sessions |
|||
* UserInfo endpoint session validation is mandatory, invalid sessions will result in request rejection |
|||
@ -1,76 +0,0 @@ |
|||
# LINGYUN.Abp.OpenIddict.AspNetCore.Session |
|||
|
|||
[](https://abp.io) |
|||
[](https://www.nuget.org/packages/LINGYUN.Abp.OpenIddict.AspNetCore.Session) |
|||
|
|||
## 简介 |
|||
|
|||
`LINGYUN.Abp.OpenIddict.AspNetCore.Session` 是 OpenIddict 的会话管理扩展模块,提供了用户会话的持久化、验证和撤销功能。 |
|||
|
|||
[English](./README.EN.md) |
|||
|
|||
## 功能特性 |
|||
|
|||
* 用户会话管理 |
|||
* 登录时自动持久化会话 |
|||
* 登出时自动终止会话 |
|||
* 令牌撤销时自动终止会话 |
|||
* UserInfo 端点会话验证 |
|||
|
|||
* 多租户支持 |
|||
* 会话管理支持多租户场景 |
|||
* 租户隔离的会话存储 |
|||
|
|||
* 可配置的会话持久化 |
|||
* 支持配置需要持久化会话的授权类型 |
|||
* 默认支持密码授权类型 |
|||
|
|||
## 安装 |
|||
|
|||
```bash |
|||
dotnet add package LINGYUN.Abp.OpenIddict.AspNetCore.Session |
|||
``` |
|||
|
|||
## 使用 |
|||
|
|||
1. 添加 `[DependsOn(typeof(AbpOpenIddictAspNetCoreSessionModule))]` 到你的模块类。 |
|||
|
|||
2. 配置会话选项: |
|||
|
|||
```csharp |
|||
Configure<IdentitySessionSignInOptions>(options => |
|||
{ |
|||
options.SignInSessionEnabled = true; // 启用登录会话 |
|||
options.SignOutSessionEnabled = true; // 启用登出会话 |
|||
}); |
|||
|
|||
Configure<AbpOpenIddictAspNetCoreSessionOptions>(options => |
|||
{ |
|||
// 配置需要持久化会话的授权类型 |
|||
options.PersistentSessionGrantTypes.Add(GrantTypes.Password); |
|||
options.PersistentSessionGrantTypes.Add("custom_grant_type"); |
|||
}); |
|||
``` |
|||
|
|||
## 工作流程 |
|||
|
|||
1. 用户登录 |
|||
* 当用户通过配置的授权类型登录成功时 |
|||
* 系统自动创建并持久化会话信息 |
|||
|
|||
2. 会话验证 |
|||
* 当用户访问 UserInfo 端点时 |
|||
* 系统自动验证会话是否有效 |
|||
* 如果会话已过期或无效,返回相应的错误 |
|||
|
|||
3. 会话终止 |
|||
* 用户主动登出时自动终止会话 |
|||
* 令牌撤销时自动终止相关会话 |
|||
* 支持多终端同时登录的会话管理 |
|||
|
|||
## 注意事项 |
|||
|
|||
* 会话持久化仅对配置的授权类型生效 |
|||
* 会话验证在多租户环境中会自动切换租户上下文 |
|||
* 令牌撤销会同时终止相关的用户会话 |
|||
* UserInfo 端点的会话验证是强制的,无效会话将导致请求被拒绝 |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue