简体   繁体   English

Owin身份验证单点注销

[英]Owin Authentication Single Sign-Out

I've got a custom Authentication middleware working for single sign-on. 我有一个用于单点登录的自定义身份验证中间件。 I'm wondering how I should go about implementing a single sign-out solution. 我想知道如何实现单一注销解决方案。

I need to call Authentication.Signout() to signout of my application, but I then need to redirect the user to the sign out endpoint of our custom STS. 我需要调用Authentication.Signout()来注销我的应用程序,但随后需要将用户重定向到我们的自定义STS的注销端点。 Where should I handle this? 我应该在哪里处理? Invoke ? Invoke ApplyResponseGrant ? ApplyResponseGrant Not in the handler at all, but just a manual redirect? 根本不在处理程序中,而只是手动重定向?

edit: This is an MVC app. 编辑:这是一个MVC应用程序。 I have everything working EXCEPT linking the local logout to logging out of the STS. 除了将本地登出链接到STS登出之外,我一切正常。 Adding my existing code here would do nothing but obfuscate my question, IMO. 在这里添加我现有的代码只会混淆我的问题,IMO。 If there is a specific piece of code that would help, let me know and I'll add it. 如果有一段特定的代码会有所帮助,请告诉我,我将添加它。

Ideally, I'd like some sort of event or flag that tells me the user is signing out, and then change the response into a 302 to the external logout. 理想情况下,我想要某种事件或标志来告诉我用户正在注销,然后将响应更改为外部注销的302。 If I put this code in the ApplyResponseGrant , I have a feeling it will prevent the CookieAuthentication middleware from clearing the auth cookie. 如果我将此代码放入ApplyResponseGrant ,我会感觉到它将阻止CookieAuthentication中间件清除auth cookie。 If I put this code in the Logout controller action (after a call to Authentication.SignOut() ), then I leave it up to each application to handle the single sign off. 如果将这段代码放入“注销”控制器操作中(在Authentication.SignOut()调用之后),则将其留给每个应用程序来处理单点注销。

I got it working. 我知道了 Here's what I did. 这就是我所做的。

In my AccountController , I added a Logout action that returns a Redirect("/signout-custom") . 在我的AccountController ,添加了一个Logout操作,该操作返回Redirect("/signout-custom")

In my OWIN handler, I watch for that URL in the Invoke method, call my remote sign out endpoint, the local sign out method, and stop OWIN processing. 在我的OWIN处理程序中,我在Invoke方法中监视该URL,调用远程注销端点,本地注销方法,并停止OWIN处理。

public override async Task<bool> InvokeAsync() {
    //other code

    if (Request.Path == Options.LogoutCallbackPath) {
        Context.Authentication.SignOut(Options.AuthenticationType);
        Response.Redirect(WebUtilities.AddQueryString(Options.ClauthLogoutUri, "returnUrl", "http://localhost:62506/Home/About"));
        return true;
    }

    //other code

}

The redirect does not interrupt the OWIN flow, so the CookieAuthentication middleware still runs and clears the local auth cookie as it should. 重定向不会中断OWIN流,因此CookieAuthentication中间件仍将运行并按应有的方式清除本地身份验证cookie。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM