Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

Missing prefix "saml:" when Using "Microsoft.IdentityModel.Tokens.Saml2" to make SAML V2.0

$
0
0

why can SAML2 produce a SAML where it use the prefix "SAML:" Like in this exemple:

   <?xml version="1.0" encoding="utf-8"?>
   <saml:Assertion ID="_51bc8a37-0b6d-4e13-81e9-e1778a9b4dd3" IssueInstant="2012-10-10T19:32:07.526Z" Version="2.0" xmlns="urn:oasis:names:tc:SAML:2.0:assertion">
    <saml:Issuer>someidentifier</Issuer>
    <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
     <ds:SignedInfo>
      <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
      <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
      <ds:Reference URI="#_51bc8a37-0b6d-4e13-81e9-e1778a9b4dd3">
       <ds:Transforms>
        <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
        <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
       </ds:Transforms>
       <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
       <ds:DigestValue>N3UrIhpT+EXn+CeMiaq98v4n6vWw=</ds:DigestValue>
      </ds:Reference>
     </ds:SignedInfo>
<ds:SignatureValue>ACDCBN55g2FTo82jWjfN67BQB7XyC1UxUIqr6iAGfu85O2P7WCkqDxPhsaveOOVkNgz1r4KkSEAdFdv5sh4xCumooUVAiQXYFMgGz6QSNjdsxUurrmetyrDLQOtU2phuAykY9bF4kNYuYBgvDygCq6gbv8DR+M83WbKFMHRy7nYkrHZg0DJw56aiHnZvZQr/VyIsSvxGU7ra9ED4Tbe26oWte8ysb71yAZKqcEzzFKZU1BmMoApwJU3DLVqHo5r335ayPYxcsvm3LJ3vIDx+ql3tEKFSlt2OLBYSMlhCGYbyxMwAmzWzgv53zx1DiXrBxsSFzrbqk7y4PNx2eE0NciA==</ds:SignatureValue>
     <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
      <o:SecurityTokenReference xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
       <o:KeyIdentifier ValueType="kdkT3iOnlm4C8J3oa4/KPHOyqngc=</o:KeyIdentifier">http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#ThumbprintSHA1">kdkT3iOnlm4C8J3oa4/KPHOyqngc=</o:KeyIdentifier>
      </o:SecurityTokenReference>
     </KeyInfo>
    </ds:Signature>
    <saml:Subject>
     <saml:NameID Format="urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified">12345</saml:NameID>
     <saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
     </saml:SubjectConfirmation>
    </saml:Subject>
    <saml:Conditions NotBefore="2012-10-10T19:31:37.526Z" NotOnOrAfter="2012-10-10T19:32:37.526Z">
    </saml:Conditions>
    <saml:AttributeStatement>
     <saml:Attribute Name="userud">
      <saml:AttributeValue>999999</saml:AttributeValue>
     </saml:Attribute>
    </saml:AttributeStatement>
   </saml:Assertion>

 

 

but all I can produce is (where's the "SAML" prefix?):


   <?xml version="1.0" encoding="utf-8"?>
   <Assertion ID="_51bc8a37-0b6d-4e13-81e9-e1778a9b4dd3" IssueInstant="2012-10-10T19:32:07.526Z" Version="2.0" xmlns="urn:oasis:names:tc:2.0:assertion">
    <Issuer>someidentifier</Issuer>
    <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
     <ds:SignedInfo>
      <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
      <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
      <ds:Reference URI="#_51bc8a37-0b6d-4e13-81e9-e1778a9b4dd3">
       <ds:Transforms>
        <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
        <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
       </ds:Transforms>
       <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
       <ds:DigestValue>N3UrIhpT+EXn+CeMiaq98v4n6vWw=</ds:DigestValue>
      </ds:Reference>
     </ds:SignedInfo>
     <ds:SignatureValue>ACDCBN55g2FTo82jWjfN67BQB7XyC1UxUIqr6iAGfu85O2P7WCkqDxPhsaveOOVkNgz1r4KkSEAdFdv5sh4xCumooUVAiQXYFMgGz6QSNjdsxUurrmetyrDLQOtU2phuAykY9bF4kNYuYBgvDygCq6gbv8DR+M83WbKFMHRy7nYkrHZg0DJw56aiHnZvZQr/VyIsSvxGU7ra9ED4Tbe26oWte8ysb71yAZKqcEzzFKZU1BmMoApwJU3DLVqHo5r335ayPYxcsvm3LJ3vIDx+ql3tEKFSlt2OLBYSMlhCGYbyxMwAmzWzgv53zx1DiXrBxsSFzrbqk7y4PNx2eE0NciA==</ds:SignatureValue>
     <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
      <o:SecurityTokenReference xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
       <o:KeyIdentifier ValueType="kdkT3iOnlm4C8J3o4/KPHOyqngc=</o:KeyIdentifier">http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#ThumbprintSHA1">kdkT3iOnlm4C8J3o4/KPHOyqngc=</o:KeyIdentifier>
      </o:SecurityTokenReference>
     </KeyInfo>
    </ds:Signature>
    <Subject>
     <NameID Format="urn:oasis:names:tc:2.0:attrname-format:unspecified">12345</NameID>
     <SubjectConfirmation Method="urn:oasis:names:tc:2.0:cm:bearer">
     </SubjectConfirmation>
    </Subject>
    <Conditions NotBefore="2012-10-10T19:31:37.526Z" NotOnOrAfter="2012-10-10T19:32:37.526Z">
    </Conditions>
    <AttributeStatement>
     <Attribute Name="userud">
      <AttributeValue>999999</AttributeValue>
     </Attribute>
    </AttributeStatement>
   </Assertion>

 

 

 

 

 

 

 

 

 

Here is my code:


 
   Saml2NameIdentifier assertionNameIdentifier = new Saml2NameIdentifier("someidentifier");
   Saml2Assertion assertion = new Saml2Assertion(assertionNameIdentifier);
   assertion.Id = new Saml2Id(SamlAssertionID);
   assertion.IssueInstant = dtIssueInstant;
   assertion.Conditions = new Saml2Conditions();
   assertion.Conditions.NotBefore = dtNotBefore;
   assertion.Conditions.NotOnOrAfter = dtNotOnOrAfter;
   //
   // Create some SAML subject.
   assertion.Subject = new Saml2Subject();
   assertion.Subject.NameId = new Saml2NameIdentifier("12345");
   assertion.Subject.NameId.Format = new Uri("urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified");
   
   //
   // Now create the SAML statement containing one attribute and one subject.
   Saml2AttributeStatement samlAttributeStatement = new Saml2AttributeStatement();
   
   //
   // Create one SAML attribute with few values.
   Saml2Attribute attr = null;
   
   attr = new Saml2Attribute("userid");
   attr.FriendlyName = "userid";
   attr.Values.Add("999999");
   samlAttributeStatement.Attributes.Add(attr);
   
   // Append the statement to the SAML assertion.
   assertion.Statements.Add(samlAttributeStatement);
   
   
   /**************************************************************
   * END createSamlAssertion()
   **************************************************************/
   
   //
   // Signing credentials are consisted
   // of private key in the certificate (see above),
   // the signature algorithm, security algortihm and key identifier.
   assertion.SigningCredentials =
   new SigningCredentials(signingKey, SecurityAlgorithms.RsaSha1Signature,
                   SecurityAlgorithms.Sha1Digest,
                   new SecurityKeyIdentifier(new X509ThumbprintKeyIdentifierClause(SigningCert)));
   
   
   
   // Finally create the SamlSecurityToken from the assertion
   Saml2SecurityToken samlToken = new Saml2SecurityToken(assertion);
   
   
   var tokenhandler = new Microsoft.IdentityModel.Tokens.Saml2.Saml2SecurityTokenHandler();
   
   var settings = new XmlWriterSettings();
   settings.Indent = false;
   settings.Encoding = Encoding.UTF8;
   
   using (var xWriter = XmlWriter.Create(@"c:\saml2.xml", settings))
   {
      
       Debug.WriteLine(xWriter.LookupPrefix("urn:oasis:names:tc:SAML:2.0:assertion"));
       tokenhandler.WriteToken(xWriter, samlToken);
       xWriter.Flush();
       xWriter.Close();
   }

 


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>