2

WIF 4.5 と WS-Trust を使用して ADFS から SAML アサーションを取得しようとしています。これにより、そのアサーションをサービス プロバイダーに送信して OAuth チケットを取得できます。

実際、SAML アサーションを取得できましたが、SubjectConfirmationData の Recipient 属性が受信されないため、有効なものではありません。そして、それは必須のデータムです。

コンソール アプリケーションでテストを行っています (したがって、Fiddler を使用して確認したように、認証情報を使用して実行され、アサーションを受け取る前に Kerberos ネゴシエーションを実行します)。そうすることでトークンを取得しています ( Windows 資格情報と .net 4.5 WIF を使用した RequestSecurityTokenに基づく):

public static string GetStsToken()
{
    try
    {
        EndpointReference appliesToEp = new EndpointReference(ENDPOINT_REFERENCE_URI);

        EndpointAddress stsEp = new EndpointAddress(
                new Uri("https://<ADFS-SERVER>/adfs/services/trust/2005/windowstransport"),
                EndpointIdentity.CreateSpnIdentity(ADFS_SPN));

        WS2007HttpBinding msgBinding = new WS2007HttpBinding(SecurityMode.Transport, false);
        msgBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
        msgBinding.Security.Message.EstablishSecurityContext = false;
        msgBinding.Security.Message.NegotiateServiceCredential = false;
        msgBinding.Security.Message.ClientCredentialType = MessageCredentialType.None;

        using (WSTrustChannelFactory factory = new WSTrustChannelFactory(msgBinding, stsEp))
        {
            factory.Credentials.SupportInteractive = false;
            factory.TrustVersion = TrustVersion.WSTrustFeb2005;

            RequestSecurityToken myRst = 
                new RequestSecurityToken(RequestTypes.Issue, KeyTypes.Bearer)
                {
                    AppliesTo = appliesToEp,
                    TokenType = "urn:oasis:names:tc:SAML:2.0:assertion"
                };
            IWSTrustChannelContract channel = factory.CreateChannel();
            GenericXmlSecurityToken stsToken = channel.Issue(myRst) as GenericXmlSecurityToken;

            if (stsToken != null)
            {
                return stsToken.TokenXml.OuterXml;
            }
            else
            {
                // SOME WARNING IS ISSUED
            }
        }
    }
    catch (Exception ex)
    {
        // THE EXCEPTION IS REGISTERED
    }

    return null;
}

このコードでは、送信されるリクエストは次のとおりです。

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
  <s:Header>
    <a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue</a:Action>
    <a:MessageID>urn:uuid:8c221169-52b2-42bf-87f8-7089b6feb0a9</a:MessageID>
    <a:ReplyTo>
      <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
    </a:ReplyTo>
    <a:To s:mustUnderstand="1">https://ADFS-SERVER/adfs/services/trust/2005/windowstransport</a:To>
  </s:Header>
  <s:Body>
    <t:RequestSecurityToken xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust">
      <wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
        <wsa:EndpointReference xmlns:wsa="http://www.w3.org/2005/08/addressing">
          <wsa:Address>ENDPOINT_REFERENCE</wsa:Address>
        </wsa:EndpointReference>
      </wsp:AppliesTo>
      <t:KeySize>0</t:KeySize>
      <t:KeyType>http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKey</t:KeyType>
      <t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType>
      <t:TokenType>urn:oasis:names:tc:SAML:2.0:assertion</t:TokenType>
    </t:RequestSecurityToken>
  </s:Body>
</s:Envelope>

受信したアサーションは有効なようですが、SubjectConfirmationData に受信者が含まれていないため、そのアサーションをサービス プロバイダーに送信すると、認証に失敗します。

サーバーにa を送信する Web IdP Initiated Login を使用し、samlp:AuthnRequestその場合に ADFS が発行する取得済みの SAML アサーションを (再び Fiddler を使用して) デコードすると、受信者属性が受信され、SSO が機能します。アサーションを取得するために使用される方法が異なることがわかります (この場合は Web-SSO が使用されます) が、どちらの場合も依拠当事者は同じであるため、発行されるアサーションは類似しているはずです。

ADFS から WS-Trust を使用してトークンを取得するときに、適切な受信者を受け取る方法はありますか?

4

1 に答える 1