【问题标题】:IdentityServer4 Handling Logout CorrectlyIdentityServer4 正确处理注销
【发布时间】:2017-05-24 04:28:00
【问题描述】:

我有一个处理登录功能的 IndentityServer4 项目和一个单独的 MVCClient,我需要有一个来自 MVC 客户端的注销功能,但是查看相同的只是有这个(MVC 客户端):

public async Task Logout()
    {
        await HttpContext.Authentication.SignOutAsync("Cookies");
        await HttpContext.Authentication.SignOutAsync("oidc");
    }

但在 identityserver4 项目中,有一个更复杂的注销,它似乎可以做更多的事情:

[HttpPost]
    [ValidateAntiForgeryToken]
    [AllowAnonymous]
    public async Task<IActionResult> Logout(LogoutViewModel model)
    {
        var vm = await _account.BuildLoggedOutViewModelAsync(model.LogoutId);
        if (vm.TriggerExternalSignout)
        {
            string url = Url.Action("Logout", new { logoutId = vm.LogoutId });
            try
            {
                // hack: try/catch to handle social providers that throw
                await HttpContext.Authentication.SignOutAsync(vm.ExternalAuthenticationScheme,
                    new AuthenticationProperties { RedirectUri = url });
            }
            catch (NotSupportedException) // this is for the external providers that don't have signout
            {
            }
            catch (InvalidOperationException) // this is for Windows/Negotiate
            {
            }
        }

        // delete authentication cookie
        await _signInManager.SignOutAsync();

        return View("LoggedOut", vm);
    }

有人能解释一下客户端真正需要什么的逻辑吗?

【问题讨论】:

    标签: asp.net-core identityserver4


    【解决方案1】:

    在MVC客户端中使用了第一种Logout方法。 第二个代码属于 IdentityServer 服务。

    第一个 Logout 初始化注销过程的某些状态并重定向到 IdentityServer 上的 Logout 视图(如果您查看示例,IdentityServer AccountController 代码中有两个 Logout:一个用于注销验证视图和一个 POST 处理程序)。

    【讨论】:

      猜你喜欢
      • 2019-01-31
      • 1970-01-01
      • 2018-01-15
      • 2018-08-13
      • 2010-09-22
      • 2013-09-27
      • 1970-01-01
      • 2016-01-02
      • 2021-01-17
      相关资源
      最近更新 更多