【发布时间】:2021-08-14 19:02:42
【问题描述】:
基本问题: 我有一个使用 EKOAPP 作为 OpenIdConnect 的外部身份验证提供程序的 APS.NET Core Web 应用程序。我希望我的用户在完成工作后能够退出,但显然 EKOAPP 没有实现会话管理标准。
基本上,从我目前发现的情况来看,从 EKOAPP 实际注销用户的唯一方法是向https://app-h1.eu.ekoapp.com/api/v1/auth/logout 发出 POST 请求,从而使用某种会话 cookie 来识别用户。因此,仅使用 HttpClient 或类似方式发送发布请求是行不通的,因为该 cookie 在后端不可用(因为它来自外部 url)。这意味着某种重定向是不可避免的(据我所知)。
首先,只是尝试的基本尝试:
[HttpPost()]
public async Task Logout()
{
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
await HttpContext.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme);
// with or without return Redirect("/Home/Index");
}
或
[HttpPost()]
public async Task<IActionResult> Logout()
{
return new SignOutResult(new[] {
OpenIdConnectDefaults.AuthenticationScheme,
CookieAuthenticationDefaults.AuthenticationScheme
});
}
只是触发“无法重定向到结束会话端点,退出时配置可能丢失或无效。” => 见Cannot redirect to the end session endpoint, the configuration may be missing or invalid OpenIdConnect SignOutAsync
坦率地说,尝试从那里实施解决方案,什么都没有。据我从浏览器网络日志中可以看出,它甚至都懒得尝试调用注销 url。
对注销有用的一件事是:
[HttpPost()]
public async Task<IActionResult> Logout()
{
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
return RedirectPreserveMethod("https://app-h1.eu.ekoapp.com/api/v1/auth/logout");
}
编辑-开始 实际上,它似乎只是起作用,因为它再次显示了登录屏幕 - 但是用户实际上并没有退出。我想我必须放弃这个... 编辑-结束
但是,用户最终会进入 EKOAPP 的登录屏幕,并且在实际登录时停留在 EKOAPP 而不是返回到我的应用程序。
我也尝试了以前端为中心的方法:
$("#logout").on("click", function () {
$.ajax({
url: "https://app-h1.eu.ekoapp.com/api/v1/auth/logout",
xhrFields: {
withCredentials: !0
},
headers: {
ajax: !0
},
method: "post"
}).done(function () {
location = "/Home/Index";
});
})
不幸的是,这只会触发跨域请求异常......
有什么想法吗?这甚至可能是我想要实现的目标吗?
【问题讨论】:
标签: javascript c# asp.net-mvc asp.net-core openid-connect