identityserver4 - 仅在 IdentityServer4 中注销客户端

标签 identityserver4

有没有办法使用 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/

相关文章:

scope - Identity Server 4 - 如何在实际用例中应用 ApiScope?

c# - IdentityServer4 的 AddSigningCredential

identityserver4 - 如何在IdentityServer4上实现缓存?

c# - 无法从 : 'https://ids.com/.well-known/openid-configuration' 检索文档

oauth-2.0 - 客户端凭据流的访问 token 中的 invalid_scope 错误

c# - ASP.NET Core IdentityServer4 - 声明列表

c# - IdentityServer4 中 token 端点的无效 HTTP 请求

.net - 为什么 Azure 应用服务找不到我的 GoDaddy 证书?

authentication - 身份服务器如何在 API 或我们使用 Authorize 属性时验证 token ?

c# - 如何以面向 future 的方式从 SPA 正确获取 IDS4 中的 token ?