Skip to content

Commit 50d01e4

Browse files
committed
Requested attribute fix 2
1 parent 84e1ae4 commit 50d01e4

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/ITfoxtec.Identity.Saml2/Schemas/Metadata/RequestedAttribute.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Xml.Linq;
34
using System.Xml.Schema;
45

@@ -31,6 +32,8 @@ public RequestedAttribute(string name, string attributeValue, bool isRequired =
3132

3233
public string AttributeValueType { get; set; } = "xs:string";
3334

35+
public string AttributeValueDataTypeNamespace { get; set; } = XmlSchema.Namespace;
36+
3437
public string AttributeValueTypeNamespace { get; set; } = XmlSchema.InstanceNamespace;
3538

3639
public XElement ToXElement()
@@ -54,13 +57,27 @@ protected IEnumerable<XObject> GetXContent()
5457
Value = AttributeValue
5558
};
5659
attribVal.Add(new XAttribute(Saml2MetadataConstants.SamlAssertionNamespaceNameX, Saml2MetadataConstants.SamlAssertionNamespace));
57-
if (!string.IsNullOrWhiteSpace(AttributeValueType) && !string.IsNullOrWhiteSpace(AttributeValueTypeNamespace))
60+
if (!string.IsNullOrWhiteSpace(AttributeValueType) && TryGetAttributeValueTypeNamespaceName(out var attributeValueTypeNamespaceName) && !string.IsNullOrWhiteSpace(AttributeValueDataTypeNamespace) && !string.IsNullOrWhiteSpace(AttributeValueTypeNamespace))
5861
{
59-
attribVal.Add(new XAttribute(Saml2MetadataConstants.XsiNamespaceNameX, AttributeValueTypeNamespace));
62+
attribVal.Add(new XAttribute(XNamespace.Xmlns + attributeValueTypeNamespaceName, AttributeValueDataTypeNamespace));
63+
attribVal.Add(new XAttribute(Saml2MetadataConstants.XsiInstanceNamespaceNameX, AttributeValueTypeNamespace));
6064
attribVal.Add(new XAttribute(XNamespace.Get(AttributeValueTypeNamespace) + Saml2MetadataConstants.Message.Type, AttributeValueType));
6165
}
6266
yield return attribVal;
6367
}
6468
}
69+
70+
private bool TryGetAttributeValueTypeNamespaceName(out string attributeValueTypeNamespaceName)
71+
{
72+
var splitValues = AttributeValueType?.Split(':');
73+
if (splitValues?.Length == 2)
74+
{
75+
attributeValueTypeNamespaceName = splitValues[0];
76+
return true;
77+
}
78+
79+
attributeValueTypeNamespaceName = null;
80+
return false;
81+
}
6582
}
6683
}

src/ITfoxtec.Identity.Saml2/Schemas/Metadata/Saml2MetadataConstants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class Saml2MetadataConstants
3939
/// <summary>
4040
/// Xsi namespace name.
4141
/// </summary>
42-
public static readonly XName XsiNamespaceNameX = XNamespace.Xmlns + "xsi";
42+
public static readonly XName XsiInstanceNamespaceNameX = XNamespace.Xmlns + "xis";
4343

4444
public const string AttributeNameFormat = "urn:oasis:names:tc:SAML:2.0:attrname-format:basic";
4545
public const string AttributeNameFormatUri = "urn:oasis:names:tc:SAML:2.0:attrname-format:uri";

0 commit comments

Comments
 (0)