SubjectConfirmationData is adding a blank attribute

When I use this code in creating the SAML2 response:

Snippet// Subject
Subject subject = new Subject(new NameID(Guid.NewGuid().ToString()));
SubjectConfirmation subjectConfirmation = new SubjectConfirmation(SAMLIdentifiers.SubjectConfirmationMethods.Bearer);
subjectConfirmation.SubjectConfirmationData = new SubjectConfirmationData { Recipient = GetUrl() };
subject.SubjectConfirmations.Add(subjectConfirmation);samlAssertion.Subject = subject;

I get this result:

<saml:SubjectConfirmation Method=“urn:oasis:names:tc:SAML:2.0:cm:bearer”>
<saml:SubjectConfirmationData=“” Recipient=“https://xxx.yyy.com/SAML2/POST” />
</saml:SubjectConfirmation>

I don’t want <saml:SubjectConfirmationData=“”, I just want: <saml:SubjectConfirmationData (IE no =“”). What am I doing wrong? How can I elliminate this?

I don’t get the same result as you. The result you get isn’t well-formed XML as the SubjectConfirmationData is an XML element but also appears to be an attribute name.
How did you display this result? Did you use samlAssertion.ToString()?


[quote]
ComponentSpace - Monday, May 9, 2016
I don't get the same result as you. The result you get isn't well-formed XML as the SubjectConfirmationData is an XML element but also appears to be an attribute name.
How did you display this result? Did you use samlAssertion.ToString()?


[/quote]

Yes I did use sanlAssertion.ToString().

And yes, it is not well formed XML, which, of course is the problem I'm having.

I’m surprised you’re not seeing well formed XML.
Our implementation of SAMLSertion.ToString() firstly converts the SAMLAssertion object into an XmlElement. It then returns XmlElement.OuterXml.
Here’s the code I ran.
SAMLAssertion samlAssertion = new SAMLAssertion();
Subject subject = new Subject(new NameID(Guid.NewGuid().ToString()));
SubjectConfirmation subjectConfirmation = new SubjectConfirmation(SAMLIdentifiers.SubjectConfirmationMethods.Bearer);
subjectConfirmation.SubjectConfirmationData = new SubjectConfirmationData { Recipient = “<a href=“https://xxx.yyy.com/SAML2/POST””>https://xxx.yyy.com/SAML2/POST" };
subject.SubjectConfirmations.Add(subjectConfirmation);
samlAssertion.Subject = subject;
Console.WriteLine(samlAssertion.ToString());

The output is:
<saml:Assertion Version=“2.0” ID=“_2dcedd2f-d624-4ef9-9f8a-0053bea06975” IssueInstant=“2016-05-10T22:59:37.892Z” xmlns:saml=“urn:oasis:names:tc:SAML:2.0:assertion”>saml:Subjectsaml:NameIDe4a1a898-7a22-45d9-838d-75a36dfabf98</saml:NameID><saml:SubjectConfirmation Method=“urn:oasis:names:tc:SAML:2.0:cm:bearer”><saml:SubjectConfirmationData Recipient=“<a href=“https://xxx.yyy.com/SAML2/POST””>https://xxx.yyy.com/SAML2/POST" /></saml:SubjectConfirmation></saml:Subject></saml:Assertion>

Could you please try this code in a console application and see if you get the same result as me?

[quote]
ComponentSpace - Tuesday, May 10, 2016
I'm surprised you're not seeing well formed XML.
Our implementation of SAMLSertion.ToString() firstly converts the SAMLAssertion object into an XmlElement. It then returns XmlElement.OuterXml.
Here's the code I ran.
SAMLAssertion samlAssertion = new SAMLAssertion();
Subject subject = new Subject(new NameID(Guid.NewGuid().ToString()));
SubjectConfirmation subjectConfirmation = new SubjectConfirmation(SAMLIdentifiers.SubjectConfirmationMethods.Bearer);
subjectConfirmation.SubjectConfirmationData = new SubjectConfirmationData { Recipient = "https://xxx.yyy.com/SAML2/POST" };
subject.SubjectConfirmations.Add(subjectConfirmation);
samlAssertion.Subject = subject;
Console.WriteLine(samlAssertion.ToString());

The output is:
e4a1a898-7a22-45d9-838d-75a36dfabf98https://xxx.yyy.com/SAML2/POST" />

Could you please try this code in a console application and see if you get the same result as me?
[/quote]

Yes I do. Thanks. Maybe my problem was doing the ToString()?? Thanks for the help.

You’re welcome.