gpt4 book ai didi

angular - 从 Identity Server 4 注销不会从客户端注销

转载 作者:行者123 更新时间:2023-12-04 11:27:21 25 4
gpt4 key购买 nike

我有类似的问题 https://github.com/IdentityServer/IdentityServer4/issues/3153

我正在使用 Asp Net Identity 和 EF Core 组合示例,一切正常,数据库、播种、api 调用,除了我尝试从 IS 页面注销时。它不会删除 .AspNetCore.Cookies这是保持用户登录客户端的方式。

    [HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Logout(LogoutInputModel model)
{

// build a model so the logged out page knows what to display
var vm = await BuildLoggedOutViewModelAsync(model.LogoutId);

if (User?.Identity.IsAuthenticated == true)
{
_log.LogCustomInfo(LoggingType.Information, "<AUDIT>" + "Logout: User Is Authenticated" + "</AUDIT>");

try
{
await _signInManager.SignOutAsync();
await HttpContext.SignOutAsync(IdentityConstants.ApplicationScheme);
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
// raise the logout event
await _events.RaiseAsync(new UserLogoutSuccessEvent(User.GetSubjectId(), User.GetDisplayName()));
}
catch (NotSupportedException)
{
_log.LogCustomInfo(LoggingType.Information, "<AUDIT>" + "Logout: SignOutAsync Not Supported" + "</AUDIT>");
}

}

/* https://github.com/IdentityServer/IdentityServer4/issues/855 */
// check if we need to trigger sign-out at an upstream identity provider

// delete local authentication cookie
Response.Cookies.Delete(".AspNetCore.Identity.Application");
Response.Cookies.Delete("idserv.external");
Response.Cookies.Delete("idserv.session");


_log.LogCustomInfo(LoggingType.Information, "<AUDIT>" + "Logout: Trigger external signout " + vm.TriggerExternalSignout + "</AUDIT>");

if (vm.TriggerExternalSignout)
{

// build a return URL so the upstream provider will redirect back
// to us after the user has logged out. this allows us to then
// complete our single sign-out processing.
string url = Url.Action("Logout", new { logoutId = vm.LogoutId });
//url = _configuration["AppSettings:PostLogoutRedirectUri"];
url = vm.PostLogoutRedirectUri;
//url = "redirect.html";
// this triggers a redirect to the external provider for sign-out
_log.LogCustomInfo(LoggingType.Information, "<AUDIT>" + "Logout: Redirect to " + url + "</AUDIT>");

return SignOut(new AuthenticationProperties { RedirectUri = url }, vm.ExternalAuthenticationScheme);
}

return View("LoggedOut", vm);
}

我在 angular 客户端和 MVC 应用程序中遇到了同样的问题。

如果我手动删除 .AspNetCore.Identity.Application客户端已注销。我正在使用 keycloak 进行身份验证并使用

    options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
options.SignOutScheme = IdentityServerConstants.SignoutScheme;

在启动IS配置选项中。

最佳答案

我知道这是一个老问题,但我遇到了同样的问题。
事实证明,我从 repo 中获得的代码没有删除问题所做的 cookie 的行。一旦我添加它,注销实际上已注销。

Response.Cookies.Delete(".AspNetCore.Identity.Application");
Response.Cookies.Delete("idserv.external");
Response.Cookies.Delete("idserv.session");
该 repo 适用于当前最新的 IdentityServer4 4.1.1 并且应该可以正常工作,因为它是演练的结果。

关于angular - 从 Identity Server 4 注销不会从客户端注销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59381153/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com