是否可以在不编辑web.config的情况下获得ACS声明?

问题描述 投票:8回答:3

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

编辑:具体来说,我想摆脱这种情况:

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

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

c# azure wif claims-based-identity acs
3个回答
10
投票

要从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部分。


1
投票

是的,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


0
投票

FeedatedAuthentication类的Handle 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;
}
© www.soinside.com 2019 - 2024. All rights reserved.