【问题标题】:Is it possible to get ACS claims without editing web.config?是否可以在不编辑 web.config 的情况下获得 ACS 声明?
【发布时间】:2012-03-17 09:47:47
【问题描述】:

是否可以在不编辑 web.config 的情况下为 azure ACS 设置领域 URL、声明类型等?你能以某种方式以编程方式设置这些必需的元素吗?

编辑: 具体来说,我想摆脱这个:

<federatedAuthentication>
    <wsFederation passiveRedirectEnabled="true" issuer="https://mynamespace.accesscontrol.windows.net/v2/wsfederation" realm="http://localhost:81/" requireHttps="false" />
</federatedAuthentication>

基本上,我不希望在网络配置中指定领域,而是在某处的代码中指定。我尝试覆盖 ClaimsAuthenticationManager 并注释掉与 FederatedAuthentication 相关的代码部分。我覆盖的身份验证代码被命中,但它不包含任何声明。我假设这是因为 FederatedAuthentication 是一个中介,它在正常到达被覆盖的 ClaimsAuthenticationManager 之前执行自己的身份验证。有没有办法以类似的方式覆盖 FederatedAuthentication 部分?或者是否有信息传递到覆盖的身份验证方法中,我可以使用这些信息来执行我自己的身份验证?

【问题讨论】:

    标签: c# azure wif claims-based-identity acs


    【解决方案1】:

    处理 FederatedAuthentication 类的 FederationConfigurationCreated 事件,例如在 Global.asax 的 Application_Start 中:

    void Application_Start(object sender, EventArgs e)
    {
        FederatedAuthentication.FederationConfigurationCreated += FCC;
    }
    
    private void FCC(object sender, FederationConfigurationCreatedEventArgs e)
    {
        e.FederationConfiguration.WsFederationConfiguration.PassiveRedirectEnabled = true;
        e.FederationConfiguration.WsFederationConfiguration.Issuer = "https://mynamespace.accesscontrol.windows.net/v2/wsfederation";
        e.FederationConfiguration.WsFederationConfiguration.Realm = "http://localhost:81/";
        e.FederationConfiguration.WsFederationConfiguration.RequireHttps = false;
    }
    

    【讨论】:

      【解决方案2】:

      为了从 web 配置中删除该 xml 行,我创建了自己的 WSFederationAuthenticationModule 覆盖旧的,如下所示:

      public class CustomWSFederationAuthenticationModule : WSFederationAuthenticationModule
      {
          protected override void InitializePropertiesFromConfiguration(string serviceName)
          {
              this.Realm = "http://localhost:81/";
              this.Issuer = "https://acsnamespace.accesscontrol.windows.net/v2/wsfederation";
              this.RequireHttps = false;
              this.PassiveRedirectEnabled = true;
          }
      }
      

      以及 web.config 的重要部分:

      <modules runAllManagedModulesForAllRequests="true">
        <add name="WSFederationAuthenticationModule" type="CustomModuleLocation.CustomWSFederationAuthenticationModule, CustomModuleLocation" preCondition="managedHandler"/>
        <add name="SessionAuthenticationModule" type="Microsoft.IdentityModel.Web.SessionAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler" />
      </modules>
      

      XML 的 federatedAuthentication 部分也被完全删除。

      【讨论】:

      • 在我的世界里就像一个魅力。谢谢!
      【解决方案3】:

      是的,FedUtil 就是这样做的。它是 Windows Identity Foundation (WIF) SDK 附带的实用程序,您可以从 Visual Studio 调用它。

      http://msdn.microsoft.com/en-us/library/ee517285.aspx

      http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=4451

      编辑:我可能误解了你的问题。 FedUtil 是一个为您配置 web.config 的实用程序。相反,如果您想在代码中配置您的应用程序,那也是可能的。 MSDN 上的 WIF 文档应该演示如何执行此操作:

      http://msdn.microsoft.com/en-us/library/ee766446.aspx

      【讨论】:

      猜你喜欢
      • 2011-10-30
      • 2016-12-10
      • 2014-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多