【发布时间】:2021-09-25 13:22:42
【问题描述】:
我的浏览器中有两个 cookie,在登录期间由 IDS4 放在那里。我需要删除它们。无法通过退出来摆脱它们(无论出于何种原因,despite the docs),我决定应用一个实用的解决方法并手动删除它们。看来那些是硬饼干。其中两个...
我试图像这样摆脱它们 - 针对所有可用的架构 as suggested。
await HttpContext.SignOutAsync("Identity.Application");
await HttpContext.SignOutAsync("Identity.External");
await HttpContext.SignOutAsync("Identity.TwoFactorRememberMe");
await HttpContext.SignOutAsync("Identity.TwoFactorUserId");
await HttpContext.SignOutAsync("idsrv");
await HttpContext.SignOutAsync("idsrv.external");
我试图通过proposed here 的明确命中来杀死他们。不过,显然 cookie 不是这样崩溃的。
Response.Cookies.Delete(".AspNetCore.Identity.Application");
Response.Cookies.Delete("idsrv.session");
这些都不会抹去它们。当然,当我重新启动浏览器时,它们确实会消失,但我需要它们在没有这种措施的情况下消失(另外,如果我要重新启动浏览器,我不需要注销用户,因为它们无论如何都会消失)。
我看到了调用HttpContext.Current 的建议,但这与我的控制器中的HttpContext 相同(根据this)。有talk about Session.Abandon,但在我的上下文中没有看到该字段。似乎有 some issues 处理这个具体问题,但我不知道 IDS4 团队是否仍未解决这些问题。
编辑
public async Task<IActionResult> LogOut([FromQuery] string logoutId)
{
LogoutRequest context = await InteractionService.GetLogoutContextAsync(logoutId);
bool? isLoggedIn = User?.Identity.IsAuthenticated;
isLoggedIn |= User.IsAuthenticated();
await HttpContext.SignOutAsync();
await HttpContext.SignOutAsync(IdentityConstants.ApplicationScheme);
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
//Response.Cookies.Delete("idsrv.session");
var output = new
{
authenticated = isLoggedIn,
clientId = context.ClientId,
sessionId = context.SessionId,
redirect = context.PostLogoutRedirectUri,
sub = context.SubjectId
};
return Ok(output);
// return SignOut();
}
【问题讨论】:
-
您的整个注销方法是什么样的? (带有 SignOutAsync 的那个)
-
@ToreNestenius 我更新了这个问题。 (可能)有趣的部分是,当 SPA 将 ID 令牌传递给 /endsession 端点时,我被重定向到此方法并获得
logoutId。将其交换为上下文会生成一个具有正确客户端 ID 的对象但只是为用户(即sub)、会话和重定向 URL 提供null。 -
为什么要删除这些cookies?用例是什么?
-
@abdusco 我注意到当这些 cookie 不存在(或过期)时,我被发送到登录屏幕。我可以通过清除商店来强制应用程序使用登录方法。我假设如果我从代码中删除它们,也会发生同样的事情。诚然,我最初预计它们会在我调用
SignOutAsync时被删除/无效,但尽管我这样做(来自 endsession 的反向通道),但用户仍然可以进入。所以最初的问题是我无法注销用户。我还注意到(注销)context具有正确的clientId但sub和returnURL 是null。
标签: c# cookies identityserver4 asp.net-core-3.1 webapi