feat: 添加 SignalR 基础设施(Hub + Redis Backplane + JWT 认证)
Some checks failed
Build and Deploy TenantApi + SkuWorker / build-and-deploy (push) Has been cancelled

- 添加 Microsoft.AspNetCore.SignalR.StackExchangeRedis NuGet 包
- 新建 OrderBoardHub(连接/断开/切换门店 Group)
- 新建 SignalRJwtEvents(WebSocket query string JWT 提取)
- Program.cs 注册 SignalR + Redis Backplane + MapHub
- JwtAuthenticationExtensions 添加 OnMessageReceived 事件
- CORS 修复 AllowAnyOrigin 与 AllowCredentials 互斥问题
This commit is contained in:
2026-02-27 13:07:51 +08:00
parent 502f80473e
commit 7c06ac3e29
5 changed files with 139 additions and 1 deletions

View File

@@ -47,6 +47,24 @@ public static class JwtAuthenticationExtensions
NameClaimType = ClaimTypes.NameIdentifier,
RoleClaimType = ClaimTypes.Role
};
// SignalR WebSocket 通过 query string 传递 JWT
options.Events = new JwtBearerEvents
{
OnMessageReceived = context =>
{
if (context.Request.Path.StartsWithSegments("/hubs"))
{
var token = context.Request.Query["access_token"];
if (!string.IsNullOrEmpty(token))
{
context.Token = token;
}
}
return Task.CompletedTask;
}
};
});
return services;