有没有办法使用 IdentityServer4 执行单点退出仅供客户端使用?使用 endsession
端点为客户端和 IdentityServer 执行单点注销没有问题。然而,我想做的是提供一种方法来强制所有客户端在下一次请求时重新进行身份验证(以获取新的声明),但不强制用户重新输入凭据。
该用例供用户编辑存储在声明中的个人资料信息。例如,他们的名字。当用户提交对此信息的更改时,所有其他客户都需要知道他们当前拥有的声明不再有效。这可以通过将用户完全注销来实现,但随后用户必须重新输入他们的 ID 和密码。
查看流程,我想我想做的是直接执行内部 EndSessionCallbackEndpoint
,而不删除 IdentityServer 本身的身份验证 cookie。
最佳答案
下面是一个可行的解决方案,但这真的感觉像是我在滥用系统。如果有人有提供预期功能的“标准”方式,请告诉我。
此解决方案将 Logout
方法更改为“嗅探”魔法 PostLogoutRedirectUri
并跳过本地身份验证 cookie 的删除。显然不是特别可扩展或优雅。
[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);
// Special post-logout URL that should only log out clients, but keep the local authentication cookie.
bool clientsOnly = !string.IsNullOrEmpty(vm.PostLogoutRedirectUri) && vm.PostLogoutRedirectUri.StartsWith("https://example.com/EditProfile");
if (User?.Identity.IsAuthenticated == true && !clientsOnly)
{
// delete local authentication cookie
await _signInManager.SignOutAsync();
// raise the logout event
await _events.RaiseAsync(new UserLogoutSuccessEvent(User.GetSubjectId(), User.GetDisplayName()));
}
// check if we need to trigger sign-out at an upstream identity provider
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 });
// this triggers a redirect to the external provider for sign-out
return SignOut(new AuthenticationProperties { RedirectUri = url }, vm.ExternalAuthenticationScheme);
}
return View("LoggedOut", vm);
}
关于identityserver4 - 仅在 IdentityServer4 中注销客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56937530/