Skip to content

Commit dff18d7

Browse files
committed
Cline fix for ype attribute of SubjectConfirmationData has incorrect casing
1 parent 48cdc0c commit dff18d7

File tree

5 files changed

+66
-1
lines changed

5 files changed

+66
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const Microsoft.IdentityModel.Tokens.Saml2.Saml2Constants.Attributes.SubjectConfirmationDataType = "Type" -> string

src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2Constants.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,17 @@ public static class Attributes
7575
public const string SessionNotOnOrAfter = "SessionNotOnOrAfter";
7676
public const string SPNameQualifier = "SPNameQualifier";
7777
public const string SPProvidedID = "SPProvidedID";
78+
/// <summary>
79+
/// W3C XML Schema standard xsi:type attribute name (lowercase)
80+
/// </summary>
7881
public const string Type = "type";
82+
83+
/// <summary>
84+
/// SAML specific xsi:type attribute (uppercase).
85+
/// Used only for SubjectConfirmationData to maintain compatibility with ADFS and other SAML implementations.
86+
/// See: https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/2894
87+
/// </summary>
88+
public const string SubjectConfirmationDataType = "Type";
7989
public const string Version = "Version";
8090
}
8191

src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2Serializer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,8 @@ protected virtual void WriteSubjectConfirmationData(XmlWriter writer, Saml2Subje
21692169

21702170
// @xsi:type
21712171
if (subjectConfirmationData.KeyInfos.Count > 0)
2172-
writer.WriteAttributeString(XmlSignatureConstants.Attributes.Type, XmlSignatureConstants.XmlSchemaNamespace, Saml2Constants.Types.KeyInfoConfirmationDataType);
2172+
// Use uppercase "Type" specifically for SAML SubjectConfirmationData for ADFS compatibility
2173+
writer.WriteAttributeString(Saml2Constants.Attributes.SubjectConfirmationDataType, Saml2Constants.Types.KeyInfoConfirmationDataType);
21732174

21742175
// @Address - optional
21752176
if (!string.IsNullOrEmpty(subjectConfirmationData.Address))

test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2SerializerTests.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,11 +626,62 @@ public Saml2Subject ReadSubjectPublic(XmlDictionaryReader reader)
626626
return base.ReadSubject(reader);
627627
}
628628

629+
public void WriteSubjectConfirmationDataPublic(XmlWriter writer, Saml2SubjectConfirmationData subjectConfirmationData)
630+
{
631+
base.WriteSubjectConfirmationData(writer, subjectConfirmationData);
632+
}
633+
629634
public void WriteProxyRestrictionPublic(XmlWriter writer, Saml2ProxyRestriction proxyRestriction)
630635
{
631636
base.WriteProxyRestriction(writer, proxyRestriction);
632637
}
633638
}
639+
640+
[Theory, MemberData(nameof(WriteSubjectConfirmationDataTheoryData), DisableDiscoveryEnumeration = true)]
641+
public void WriteSubjectConfirmationData(Saml2TheoryData theoryData)
642+
{
643+
TestUtilities.WriteHeader($"{this}.WriteSubjectConfirmationData", theoryData);
644+
var context = new CompareContext($"{this}.WriteSubjectConfirmationData, {theoryData.TestId}");
645+
try
646+
{
647+
var ms = new MemoryStream();
648+
var writer = XmlDictionaryWriter.CreateTextWriter(ms, Encoding.UTF8, false);
649+
(theoryData.Saml2Serializer as Saml2SerializerPublic).WriteSubjectConfirmationDataPublic(writer, theoryData.SubjectConfirmationData);
650+
651+
writer.Flush();
652+
var xml = Encoding.UTF8.GetString(ms.ToArray());
653+
IdentityComparer.AreEqual(xml, theoryData.Xml, context);
654+
theoryData.ExpectedException.ProcessNoException();
655+
}
656+
catch (Exception ex)
657+
{
658+
theoryData.ExpectedException.ProcessException(ex);
659+
}
660+
661+
TestUtilities.AssertFailIfErrors(context);
662+
}
663+
664+
public static TheoryData<Saml2TheoryData> WriteSubjectConfirmationDataTheoryData
665+
{
666+
get
667+
{
668+
var keyInfo = new KeyInfo();
669+
keyInfo.KeyName = "test";
670+
var confirmationData = new Saml2SubjectConfirmationData();
671+
confirmationData.KeyInfos.Add(keyInfo);
672+
673+
return new TheoryData<Saml2TheoryData>
674+
{
675+
new Saml2TheoryData
676+
{
677+
SubjectConfirmationData = confirmationData,
678+
Xml = "<saml:SubjectConfirmationData Type=\"KeyInfoConfirmationDataType\" xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\"><KeyInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><KeyName>test</KeyName></KeyInfo></saml:SubjectConfirmationData>",
679+
Saml2Serializer = new Saml2SerializerPublic(),
680+
TestId = "WriteSubjectConfirmationDataWithUppercaseType"
681+
}
682+
};
683+
}
684+
}
634685
}
635686
}
636687

test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2TheoryData.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,7 @@ public Saml2TheoryData(TokenTheoryData tokenTheoryData)
5757
public Saml2Subject Subject { get; set; }
5858

5959
public Saml2ProxyRestriction ProxyRestriction { get; set; }
60+
61+
public Saml2SubjectConfirmationData SubjectConfirmationData { get; set; }
6062
}
6163
}

0 commit comments

Comments
 (0)