【问题标题】:How can I allow both ADFS/STS and Forms authentication in the same application?如何在同一个应用程序中同时允许 ADFS/STS 和 Forms 身份验证?
【发布时间】:2016-09-21 19:54:35
【问题描述】:

我有一个当前仅适用于表单身份验证的应用程序,但现在它将使用 HTTPS/SSL 在互联网上公开,在这种情况下,它需要接受 STS/ADFS 身份验证。

我按照this MSDN article 的说明进行操作,但如何将我的应用程序设置为允许两种身份验证方法?

已应用 Web.config 设置:

<configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->

    <section name="glimpse" type="Glimpse.Core.Configuration.Section, Glimpse.Core" />
    <section name="system.identityModel" type="System.IdentityModel.Configuration.SystemIdentityModelSection, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
    <section name="system.identityModel.services" type="System.IdentityModel.Services.Configuration.SystemIdentityModelServicesSection, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</configSections>


<location path="FederationMetadata">
    <system.web>
        <authorization>
            <allow users="*" />
        </authorization>
    </system.web>
</location>
<authentication mode="None" />

<authorization>
    <deny users="?" />
</authorization>

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
        <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
        <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
        <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
        <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
        <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
        <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
        <add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />

        <add name="Glimpse" path="glimpse.axd" verb="GET" type="Glimpse.AspNet.HttpHandler, Glimpse.AspNet" preCondition="integratedMode" />
    </handlers>

    <modules>
        <add name="Glimpse" type="Glimpse.AspNet.HttpModule, Glimpse.AspNet" preCondition="integratedMode" />
        <add name="WSFederationAuthenticationModule" type="System.IdentityModel.Services.WSFederationAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />
        <add name="SessionAuthenticationModule" type="System.IdentityModel.Services.SessionAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />
    </modules>
</system.webServer>

<system.identityModel>
    <identityConfiguration>
        <audienceUris>
            <add value="https://localhost:44300/Desvio/" />
        </audienceUris>
        <issuerNameRegistry type="System.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <trustedIssuers>
                <add thumbprint="‎a527140bc9f440ebd6992ba26c6ea4758c3a2738" name="sts-dev.myserver.com" />
            </trustedIssuers>
        </issuerNameRegistry>
        <certificateValidation certificateValidationMode="None" />
    </identityConfiguration>
</system.identityModel>
<system.identityModel.services>
    <federationConfiguration>
        <cookieHandler requireSsl="false" />
        <wsFederation passiveRedirectEnabled="true" issuer="https://sts-dev.myserver.com/adfs/ls/" 
                    realm="https://localhost:44300/Desvio/" reply="https://localhost:44300/Desvio/" requireHttps="true" />
    </federationConfiguration>
</system.identityModel.services>

【问题讨论】:

标签: asp.net-mvc asp.net-mvc-3 wif adfs


【解决方案1】:

如果我理解正确,那应该相当容易。 Forms Auth 模块仅用于为本地应用程序发出 cookie 并为当前登录的用户维护会话。那么,通过验证应用中的用户名/密码或接受 SAML 令牌来获得身份验证的方式并不重要。

从技术上讲,从管道中移除 SAM 和 FAM 模块。再次将 Forms 设为您的身份验证方法,这样您就有了一个基于常规表单身份验证的应用程序。

然后,只需在您的登录端点中添加一个代码,该代码可选择接受来自 ADFS 或任何其他 STS 的传入 SAML 令牌。您可以按照我的教程进行操作

http://www.wiktorzychla.com/2014/11/simplest-saml11-federated-authentication.html

代码的关键部分非常简单

var securityToken = fam.GetSecurityToken( request );

var config = new SecurityTokenHandlerConfiguration
{
    CertificateValidator = X509CertificateValidator.None,
    IssuerNameRegistry   = new CustomIssuerNameRegistry()
};
config.AudienceRestriction.AudienceMode = AudienceUriMode.Never;

var tokenHandler = new SamlSecurityTokenHandler
{
    CertificateValidator = X509CertificateValidator.None,
    Configuration        = config
};

// validate the token and get the ClaimsIdentity out of it
var identity  = tokenHandler.ValidateToken( securityToken );

一旦您从传入的令牌中获得了用户的身份,就可以使用 Forms Auth 发出与在基于常规表单身份验证的应用程序中发出的完全相同的 cookie(请注意,在我的教程中,我在这里发出 SAM cookie这只是您不想在此处遵循的另一种可能性,因为您特别坚持使用表单 cookie)。

【讨论】:

    【解决方案2】:

    你不能。

    使用 ADFS,您可以根据 ADFS 配置选择其中一种。

    有一个例外 - 如果您有 ADFS WAP,内部 = WIA,外部 = FBA。

    或者,如果没有为 IWA 设置内部浏览器,则会弹出登录屏幕。

    【讨论】:

    • 我想你的意思是没有“本机”支持,因为我发现一些文章显示了完成此身份验证的方法。我只是不知道它是否有效,但我明天会试一试。 :)。 leastprivilege.com/2012/02/02/…, blog.elis-co.com/wif-sso-and-forms-authentication-in-asp-net
    • 酷 - 混淆了两个概念 - ADFS FBA 与 ASP.NET 表单身份验证。我过去看过那篇文章,但无法让它工作:-( IIRC,WIF 默认情况下保护整个应用程序。
    • 使用自定义属性的选项不起作用(断点从未命中),现在我将尝试为 SSO 创建一个单独的应用程序,该应用程序与主应用程序共享身份验证 cookie。跨度>
    猜你喜欢
    • 1970-01-01
    • 2021-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多