c# - 使用 IdentityServer4 进行子域多租户登录
问题描述
我正在尝试使用 identityserver4 实现多租户应用程序假设我有
- web1.local.com
- web2.local.com
当我登录到 web1.local.com 时,其他域 web2.local.com 也自动登录。
无论如何要分开这些登录名吗?
我正在考虑自定义实现IUserSession
public virtual async Task CreateSessionIdAsync(ClaimsPrincipal principal, AuthenticationProperties properties)
{
if (principal == null) throw new ArgumentNullException(nameof(principal));
if (properties == null) throw new ArgumentNullException(nameof(properties));
var currentSubjectId = (await GetUserAsync())?.GetSubjectId();
var newSubjectId = principal.GetSubjectId();
if (!properties.Items.ContainsKey(SessionIdKey) || currentSubjectId != newSubjectId)
{
properties.Items[SessionIdKey] = CryptoRandom.CreateUniqueId(16);
}
IssueSessionIdCookie(properties.Items[SessionIdKey]);
Principal = principal;
Properties = properties;
}
private void IssueSessionIdCookie(string sid)
{
if (Options.Endpoints.EnableCheckSessionEndpoint)
{
if (GetSessionIdCookieValue() != sid)
{
HttpContext.Response.Cookies.Append(
Options.Authentication.CheckSessionCookieName,
sid,
CreateSessionIdCookieOptions());
}
}
}
最好的方法是什么?
解决方案
我相信您遇到的问题是,一旦 IdentityServer 发出会话 cookie,无论最初使用哪个应用程序登录,IdentityServer 将始终跳过来自任何其他应用程序的后续请求的登录(因为最初管理的会话 cookie) .
要始终强制不同应用程序之间的身份验证,您可以在授权请求上使用“提示”查询字符串并将其设置为“登录”。更多信息可以在这里找到:http ://docs.identityserver.io/en/latest/endpoints/authorize.html?highlight=prompt
推荐阅读
- combobox - 使用唯一值 VBA excel 填充相关组合框
- dns - 域:找不到 webcafe.tech 的服务器 IP 地址
- swift - 如何随机化 Swift 字典中的值
- python - 使用explode()后数据框上的空单元格
- powershell - 使用 Powershell 压缩和修复目录中的所有 Access 数据库
- javascript - 将覆盖按钮与另一个 div 上的按钮对齐
- c# - 尝试验证收到的 qr 时出现问题
- r - R函数产生NAN,诊断。统计::优化
- php - 如何使用 PHP 访问多维 Json
- excel - VBA - 通过优化 Word Table 每一页上第一行的定位索引。Excel