在SOAP调用中使用SAML断言

时间:2020-02-14 06:12:39

标签: saml-2.0

因此,我有以下加密的SAML断言,该断言是从STS服务器获取的。我正在使用以下代码用此令牌调用SOAP端点,但是成功了:

这是正确的方法吗?

                var reader = new XmlTextReader(new StringReader(SAMLAssertionAsString));
                SecurityTokenHandlerCollection handlers =
               FederatedAuthentication.FederationConfiguration.IdentityConfiguration.SecurityTokenHandlers;

                var document = new XmlDocument { PreserveWhitespace = true };
                document.Load(reader);

                var encryptedAssertion = new SAML2.Saml20EncryptedAssertion((RSA)initiatingPartyKey.PrivateKey, document);
                encryptedAssertion.Decrypt();
                var decryptedContent = encryptedAssertion.Assertion.InnerXml;

                // read the token
                System.IdentityModel.Tokens.SecurityToken securityToken = handlers.ReadToken(decryptedContent );

                ChannelFactory<IUSIService> _channelFactory;
                _channelFactory = new ChannelFactory<IUSIService>("WS2007FederationHttpBinding_IUSIService");
                IUSIService serviceChannel = _channelFactory.CreateChannelWithIssuedToken(securityToken);
                _channelFactory.SomeService();
          <saml:EncryptedAssertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
        <xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Id="" Type="http://www.w3.org/2001/04/xmlenc#Element">
          <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc"/>
          <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
            <xenc:EncryptedKey Id="">
              <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p">
                <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
              </xenc:EncryptionMethod>
              <ds:KeyInfo>
                <wsse:SecurityTokenReference xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
                  <ds:X509Data>
                    <ds:X509IssuerSerial>
                      <ds:X509IssuerName>CN=,OU=,OU=,O=,C=AU</ds:X509IssuerName>
                      <ds:X509SerialNumber></ds:X509SerialNumber>
                    </ds:X509IssuerSerial>
                  </ds:X509Data>
                </wsse:SecurityTokenReference>
              </ds:KeyInfo>
              <xenc:CipherData>
                <xenc:CipherValue></xenc:CipherValue>
              </xenc:CipherData>
            </xenc:EncryptedKey>
          </ds:KeyInfo>
          <xenc:CipherData>
            <xenc:CipherValue></xenc:CipherValue>
          </xenc:CipherData>
        </xenc:EncryptedData>
      </saml:EncryptedAssertion>

0 个答案:

没有答案
相关问题