3

ASP.NET MVC 5アプリケーションから外部IDP用のWS-FederationでWeb SSOを使用しようとしました。ASP.NET MVC 5外部IDPでWeb SSOを使用 - WS Fedメタデータが解析されない

このシナリオでは、ASP.NETアプリケーションはサービスプロバイダです。

ログインするには、SAML HTTPリダイレクトバインディングを使用します。

外部IDP WS-FEDのメタデータ:Start.up.csで

<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" ID="id-58j8Ew5J8B7hOu51hu5qYyIGsXc-" 
        cacheDuration="P0Y0M30DT0H0M0.0S" entityID="idp:domain.com" 
        validUntil="2016-07-24T18:51:12Z"> 
    <md:IDPSSODescriptor WantAuthnRequestsSigned="true" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol"> 
    <md:KeyDescriptor use="signing"> 
     <dsig:KeyInfo xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"> 
     <dsig:X509Data> 
      <dsig:X509Certificate> 
      <!-- CERT --> 
      </dsig:X509Certificate> 
      <dsig:X509IssuerSerial> 
      <dsig:X509IssuerName><!--ISSUER--></dsig:X509IssuerName> 
      <dsig:X509SerialNumber><!--SN--></dsig:X509SerialNumber> 
      </dsig:X509IssuerSerial> 
      <dsig:X509SubjectName><!--CN--></dsig:X509SubjectName> 
     </dsig:X509Data> 
     </dsig:KeyInfo> 
    </md:KeyDescriptor> 
    <md:KeyDescriptor use="encryption"> 
     <dsig:KeyInfo xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"> 
     <dsig:X509Data> 
      <dsig:X509Certificate> 
      <!-- CERT --> 
      </dsig:X509Certificate> 
      <dsig:X509IssuerSerial> 
      <dsig:X509IssuerName> 
       <!--ISSUER--> 
      </dsig:X509IssuerName> 
      <dsig:X509SerialNumber> 
       <!--SN--> 
      </dsig:X509SerialNumber> 
      </dsig:X509IssuerSerial> 
      <dsig:X509SubjectName> 
      <!--CN--> 
      </dsig:X509SubjectName> 
     </dsig:X509Data> 
     </dsig:KeyInfo> 
     <md:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" /> 
     <md:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc" /> 
     <md:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes192-cbc" /> 
     <md:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc" /> 
     <md:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" /> 
    </md:KeyDescriptor> 
    <md:ArtifactResolutionService Binding="urn:oasis:names:tc:SAML:2.0:bindings:SOAP" 
            Location="https://domain.com/fed/idp/soap" index="1" 
            isDefault="true" /> 
    <md:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" 
          Location="https://domain.com/fed/idp/samlv20" 
          ResponseLocation="https://domain.com/fed/idp/samlv20" /> 
    <md:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" 
          Location="https://domain.com/fed/idp/samlv20" 
          ResponseLocation="https://domain.com/fed/idp/samlv20" /> 
    <md:NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:persistent</md:NameIDFormat> 
    <md:NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:transient</md:NameIDFormat> 
    <md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName</md:NameIDFormat> 
    <md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress</md:NameIDFormat> 
    <md:SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" 
          Location="https://domain.com/fed/idp/samlv20" /> 
    <md:SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" 
          Location="https://domain.com/fed/idp/samlv20" /> 
    </md:IDPSSODescriptor> 
</md:EntityDescriptor> 

認証の設定:

public partial class Startup 
    { 

     private static readonly string realm = ConfigurationManager.AppSettings["ida:Wtrealm"]; 
     private static readonly string adfsMetadata = ConfigurationManager.AppSettings["ida:ADFSMetadata"]; 


     public static bool ValidateServerCertificate(object sender, 
                X509Certificate certificate, 
                X509Chain chain, 
                SslPolicyErrors sslPolicyErrors) 
     { 
      return true; 
     } 

     public void ConfigureAuth(IAppBuilder app) 
     { 
      //only for dev purpose 
      ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate; 

      app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType); 

      app.UseCookieAuthentication(new CookieAuthenticationOptions()); 

      var wsFedOpt = new WsFederationAuthenticationOptions 
      { 
       Wtrealm = realm, 
       MetadataAddress = adfsMetadata, 
       AuthenticationType = WsFederationAuthenticationDefaults.AuthenticationType, 
       TokenValidationParameters = new TokenValidationParameters 
       { 
        SaveSigninToken = true, 
       }, 
      }; 

      app.UseWsFederationAuthentication(wsFedOpt); 
     } 
    } 

私はアプリを実行すると、私はエラーを取得する:

シーケンスには要素が含まれていません

説明:

An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: Sequence contains no elements

ソースエラー:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

スタックトレース:

[InvalidOperationException: Sequence contains no elements] System.Linq.Enumerable.First(IEnumerable`1 source) +264 Microsoft.IdentityModel.Protocols.d__1.MoveNext() +576 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58 System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) +11532712 Microsoft.IdentityModel.Protocols.d__3.MoveNext() +1236

今、私が悪いのか分からないのですか?外部IDPフェデレーションメタデータ、ASP.NET MVC設定など。

私がログイン時に外部IDPと外部SPを試したとき、それはHTTP GETを呼び出し、URIの形式は次のとおりです。

https://domain.com/fed/idp/samlv20?SAMLRequest= 

Aはその後、私は外部のIDPのログインページにリダイレクトしています。

私はローカルIDP(Identity Server v3)と同じ設定プロセスを試してみました。

私は私の地元のSPを使用する場合、認証は、ローカルIDP(Identity Serverのv3の)に基づいて構成され、それはHTTP GETを呼び出して、ログイン時のメタデータ:

https://localhost:44333/core/wsfed?wtrealm=urn%3amvc5&wctx=WsFedOwinState%3dqNRmL2H9VZcEDKooeSF5nywV2vAHUDLXRSA77oe8jyVwZtGjpgRquhqYNUPbH28vrhm55zuEBYZnRw_k2nK-a97HHv9tiYLnwt4G19i1-q0&wa=wsignin1.0&wreply=https%3a%2f%2flocalhost%3a44392%2f 

、その後、私はIDPのログインページにリダイレクトしています。

SAML HTTPリダイレクトバインディングの場合は、https://domain.com/fed/idp/samlv20?SAMLRequest=という形式のASP.NET使用URIを達成する必要があるかもしれません。

ご意見ありがとうございました。

答えて

2

混乱しているプロトコルのようです。メタデータはSAML2プロトコル(略してSAML2P)用であり、WS-Federationプロトコル用ではありません。

WS-Fedミドルウェアの代わりにSAML2Pのowinミドルウェアが必要です。 IdpにWS-Federationを使用させることができない限り、そうではありません。

+0

ありがとうございました – bolehlav

関連する問題