【问题标题】:Logout from access control service with custom STS使用自定义 STS 从访问控制服务中注销
【发布时间】:2013-09-25 18:22:27
【问题描述】:

我正在使用带有自定义 STS 的 Windows azure 访问控制服务。我可以通过 ACS 登录到我的应用程序,但我无法使用注销功能。我已在我的应用程序中尝试过此代码。

        WSFederationAuthenticationModule fam = FederatedAuthentication.WSFederationAuthenticationModule;

        try
        {
            FormsAuthentication.SignOut();
        }
        finally
        {
            fam.SignOut(true);
        }
        Page.Response.Redirect("default.aspx");

但它似乎从 ACS 注销用户,而不是从自定义 STS。我应该怎么做才能从 STS 注销。应用程序 (RP)、ACS 或 STS 中的问题可能出在哪里?

我认为 ACS 应该要求自定义 STS 注销用户,但它似乎没有这样做。我错过了什么?

【问题讨论】:

    标签: windows azure acs


    【解决方案1】:

    我创建了一个用于执行 FederatedSignout 的辅助方法,代码中包含我在此过程中发现的内容的 cmets (hth)

    public static void FederatedSignOut(string reply = null)
    {
       WSFederationAuthenticationModule fam = FederatedAuthentication.WSFederationAuthenticationModule;
    
       // Native FederatedSignOut doesn't seem to have a way for finding/registering realm for singout, get it from the FAM
       string wrealm = string.Format("wtrealm={0}", fam.Realm);
    
       // Create basic url for signout (wreply is set by native FederatedSignOut)
       string signOutUrl = WSFederationAuthenticationModule.GetFederationPassiveSignOutUrl(fam.Issuer, null, wrealm);
    
       // Check where to return, if not set ACS will use Reply address configured for the RP
       string wreply = !string.IsNullOrEmpty(reply) ? reply : (!string.IsNullOrEmpty(fam.Reply) ? fam.Reply : null);
    
       WSFederationAuthenticationModule.FederatedSignOut(new Uri(signOutUrl), !string.IsNullOrEmpty(wreply) ? new Uri(wreply) : null);
    
       // Remarks! Native FederatedSignout has an option for setting signOutUrl to null, even if the documentation tells otherwise.
       // If set to null the method will search for signoutUrl in Session token, but I couldn't find any information about how to set this. Found some Sharepoint code that use this
       // Michele Leroux Bustamante had a code example (from 2010) that also uses this form.
       // Other examples creates the signout url manually and calls redirect.
    
       // FAM has support for wsignoutcleanup1.0 right out of the box, there is no need for code to handle this.
       // That makes it even harder to understand why there are no complete FederatedSignOut method in FAM
    
       // When using native FederatedSignOut() no events for signout will be called, if you need this use the FAM SignOut methods instead.
    }
    

    此代码用于我们为带有 ACS 的 Web SSO 创建的标准 RP 库。

    【讨论】:

      【解决方案2】:

      2012 年 12 月的 ACS 更新包括对联合单点注销的支持:

      使用 WS-Federation 协议。使用 ACS 的 Web 应用程序 使用身份提供者启用单点登录 (SSO) WS-Federation 协议现在可以利用单点注销 能力。当用户退出 Web 应用程序时,ACS 可以 自动将用户从身份提供者和注销 使用相同身份提供者的其他依赖方应用程序。

      此功能对 WS-Federation 身份提供者启用,包括 Active Directory 联合服务 2.0 和 Windows Live ID (微软帐户)。为了启用单点注销,ACS 执行 WS-Federation 协议端点的以下任务:

      • ACS 识别来自身份提供者的 wsignoutcleanup1.0 消息 并通过向依赖方发送 wsignoutcleanup1.0 消息来响应 应用程序。

      • ACS 识别 wsignout1.0 并重新回复来自信赖方的消息 应用程序并通过向身份发送 wsignout1.0 消息来响应 提供者和 wsignoutcleanup1.0 消息到依赖方 应用程序。

      Code Sample: ASP.NET MVC 4 with Federated Sign-out,执行这样的操作以从 ACS 中退出:

      (请注意,Windows Identity Foundation 现在已合并到 .NET 4.5 框架中,这就是下面新命名空间的原因)

      using System.IdentityModel.Services;
      using System.IdentityModel.Services.Configuration;
      
      public ActionResult Logout()
      {
          // Load Identity Configuration
          FederationConfiguration config = FederatedAuthentication.FederationConfiguration;
      
          // Get wtrealm from WsFederationConfiguation Section
          string wtrealm = config.WsFederationConfiguration.Realm;
          string wreply;
      
          // Construct wreply value from wtrealm (This will be the return URL to your app)
          if (wtrealm.Last().Equals('/'))
          {
              wreply = wtrealm + "Logout";
          }
          else
          {
              wreply = wtrealm + "/Logout";
          }
      
          // Read the ACS Ws-Federation endpoint from web.Config
          // something like "https://<your-namespace>.accesscontrol.windows.net/v2/wsfederation"
          string wsFederationEndpoint = ConfigurationManager.AppSettings["ida:Issuer"];
      
          SignOutRequestMessage signoutRequestMessage = new SignOutRequestMessage(new Uri(wsFederationEndpoint));
      
          signoutRequestMessage.Parameters.Add("wreply", wreply);
          signoutRequestMessage.Parameters.Add("wtrealm", wtrealm);
      
          FederatedAuthentication.SessionAuthenticationModule.SignOut();
      
          string signoutUrl = signoutRequestMessage.WriteQueryString();
      
          return this.Redirect(signoutUrl);
      }
      

      【讨论】:

      • 谢谢!我一直在寻找这样的解决方案。像魅力一样工作。
      猜你喜欢
      • 2011-08-04
      • 2012-06-17
      • 1970-01-01
      • 1970-01-01
      • 2015-09-03
      • 1970-01-01
      • 1970-01-01
      • 2018-02-12
      • 2013-10-19
      相关资源
      最近更新 更多