如何在identityserver4中启用前频道或后频道注销
我正在研究当用户在identity server部署(例如)上注销时,如何断开当前登录mvc客户端的用户(例如)的连接 据我所知,identityserver4中有一个OAuth2的实现就是这样做的(和) 幸运的是,布罗克·艾伦(Brock Allen)在不到一天前刚刚推动了样品的更改: 然而,在这一点上,样本要么不完整,要么我遗漏了一些东西 在我的服务器上,我将FrontChannelLogoutUrl的值设置为,并将这段代码添加到我的mvc客户端(基本上是从示例中窃取的): 那代码永远不会被调用如何在identityserver4中启用前频道或后频道注销,identityserver4,Identityserver4,我正在研究当用户在identity server部署(例如)上注销时,如何断开当前登录mvc客户端的用户(例如)的连接 据我所知,identityserver4中有一个OAuth2的实现就是这样做的(和) 幸运的是,布罗克·艾伦(Brock Allen)在不到一天前刚刚推动了样品的更改: 然而,在这一点上,样本要么不完整,要么我遗漏了一些东西 在我的服务器上,我将FrontChannelLogoutUrl的值设置为,并将这段代码添加到我的mvc客户端(基本上是从示例中窃取的): 那代码永远不会被
所以我的问题是:我应该使用backchannel还是frontchannel;而且,如何实现它非常简单。在帐户控制器(在idserver中)上的注销操作中,确保显示LoggedOut视图,该视图依次显示调用mvc客户端回调的iFrame。与规范所说的差不多。很好地描述了如何实现前端通道注销。寻找Quickstart,因为它提供了实现所需的大部分代码 identity server中所需代码的一些要点: 在中,注销函数构建一个
LoggedOutViewModel
,并返回一个LoggedOut
视图
剩下要做的是为每个客户定义FrontChannelLogoutUri
。这通常在identity server的config.cs
public静态IEnumerable GetClients()
{
返回新列表
{
//资源所有者密码授予客户端
新客户
{
ClientId=“js”,
ClientName=“JavaScript客户端”,
AllowedGrantTypes=GrantTypes.Code,
RequirePkce=true,
RequireClientSecret=false,
重定向URI={”http://localhost:5003/callback.html" },
PostLogoutRedirectUris={”http://localhost:5003/index.html" },
FrontChannelLogoutUri=”http://localhost:5003/frontChannello"
这基本上是有效的,但它会在我刚刚注销的应用程序上调用注销,而不是其他客户端。仍在尝试找出答案why@DaImTo根据他们的规范,你的应用在技术上不应该执行注销,你的应用应该重定向到IS的结束会话端点,然后它会提示用户注销,如果你添加了可以自动注销的id_令牌提示。IS会跟踪用户导航到的应用程序,它会为用户导航到的客户端配置的每个frontchannellogoutIURi创建一个iframe,对于backchannel也是如此。IS会为您触发签出端点。请阅读底部部分
[HttpGet("frontChannello")]
public IActionResult FrontChannelLogout(string sid)
{
if (User.Identity.IsAuthenticated)
{
var currentSid = User.FindFirst("sid")?.Value ?? "";
if (string.Equals(currentSid, sid, StringComparison.Ordinal))
{
//await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
return new SignOutResult(new[] { "Cookies", "oidc" });
}
}
return NoContent();
}
[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);
...
return View("LoggedOut", vm);
}
@model LoggedOutViewModel
<div class="page-header logged-out">
<small>You are now logged out</small>
...
@if (Model.SignOutIframeUrl != null)
{
<iframe width="0" height="0" class="signout" src="@Model.SignOutIframeUrl"></iframe>
}
</div>
public static IEnumerable<Client> GetClients()
{
return new List<Client>
{
// resource owner password grant client
new Client
{
ClientId = "js",
ClientName = "JavaScript Client",
AllowedGrantTypes = GrantTypes.Code,
RequirePkce = true,
RequireClientSecret = false,
RedirectUris = { "http://localhost:5003/callback.html" },
PostLogoutRedirectUris = { "http://localhost:5003/index.html" },
FrontChannelLogoutUri = "http://localhost:5003/frontChannello"