【问题标题】:Use HttpPost for Logout in OWIN/Katana authentication manager在 OWIN/Katana 身份验证管理器中使用 HttpPost 注销
【发布时间】:2016-03-24 19:37:35
【问题描述】:

有没有办法强制 Katana 身份验证管理器使用 HttpPost 而不是 HttpGet 方法从 IdentityServer3 调用 Logout 端点?

我目前使用此方法从 IdentityServer3 调用 endsession 端点(根据this 教程):

public ActionResult Logout()
{
    // standard way with HTTP GET
    Request.GetOwinContext().Authentication.SignOut();

    return Redirect("/");
}

我需要这个,因为 URL 将有超过 2000 个字符,这会导致一些错误。

谢谢帮助

【问题讨论】:

    标签: c# asp.net-mvc owin katana identityserver3


    【解决方案1】:

    遗憾的是,OWIN 中间件不支持 HttpPost 注销操作。 作为一种解决方法,您可以手动将必要的参数发布到 结束会话端点

    我在我的 MVC5 应用程序中提供了一个链接,以便用户能够注销:

    @{
        Claim idTokenHintClaim = Request.GetOwinContext().Authentication.User.FindFirst("id_token");
        string idTokenHint = idTokenHintClaim != null
            ? idTokenHintClaim.Value
            : null;
    }
    <form action="https://.../core/endsession" method="POST" id="logoutForm">
        <input type="hidden" name="id_token_hint" value="@idTokenHint"/>
        <input type="hidden" name="post_logout_redirect_uri" value="@PostLogoutRedirectUrl"/>
    </form>
    <a href="javascript:document.getElementById('logoutForm').submit()">
        Logout
    </a>
    

    IdentityServer3 正在执行它的工作并销毁当前用户会话。之后 IdentityServer3 调用我们的@PostLogoutRedirectUrl@PostLogoutRedirectUrl 指向 MVC 应用程序的控制器方法:

    public ActionResult LogoutCallback()
    {
        HttpCookie cookie = new HttpCookie("SecureCookieName");
        cookie.HttpOnly = true;
        cookie.Expires = new DateTime(1999, 10, 12);
        Response.Cookies.Remove("SecureCookieName");
        Response.Cookies.Add(cookie);
    
        SetPasswordResetHint();
    
        return RedirectToAction("Index");
    }
    

    希望OWIN中间件能尽快加入对HttpPost方法的支持。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-24
      • 1970-01-01
      • 2020-03-11
      • 2015-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多