2016-09-21 39 views
0

我有一個應用程序,目前只適用於窗體身份驗證,但現在它會暴露在互聯網上使用HTTPS/SSL,在這種情況下,它需要接受STS/ADFS身份驗證。如何在同一個應用程序中允許ADFS/STS和表單身份驗證?

我按照以下MSDN文章中的說明操作:https://msdn.microsoft.com/en-us/library/hh291061.aspx,但是如何將我的應用程序設置爲允許兩種身份驗證方法?應用

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> 

回答

0

你不能。

對於ADFS,您可以有一個或另一個取決於ADFS配置。

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

或者如果沒有爲IWA設置內部瀏覽器,則會彈出一個登錄屏幕。

+0

我想你的意思是說沒有「原生」支持,因爲我發現一些文章展示瞭如何完成這個認證。我只是不知道它是否有效,但明天我會試一試。 :)。 https://leastprivilege.com/2012/02/02/mixing-forms-and-token-authentication-in-a-single-asp-net-application/,http://blog.elis-co.com/wif -sso-and-forms-authentication-in-asp-net/ –

+0

很酷 - 兩個概念的混淆 - ADFS FBA與ASP.NET表單身份驗證。我曾經看過那篇文章,但無法使其工作:-(IIRC,WIF默認保護整個應用程序 – nzpcmad

+0

使用自定義屬性的選項不起作用(斷點從未命中),現在我會給嘗試爲單獨的SSO應用程序與主應用程序共享身份驗證cookie。 –

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); 

一旦,使用窗體身份驗證發行在常規形式的基於auth的應用程序中發佈的cookie非常相同(請注意,在我的教程中,我發佈了一個SAM cookie,這是您不需要在這裏遵守的另一種可能性,因爲您堅持使用cookie形式)。

相關問題