InvalidOperationException: The specified type was not recognized: name='SecurityTokenServiceType', namespace='http://docs.oasis-open.org/wsfed/federation/200706', at <RoleDescriptor xmlns='urn:oasis:names:tc:SAML:2.0:metadata'>
at SAML2.Utils.Serialization.Deserialize[T](XmlReader reader) in src\SAML2\Utils\Serialization.cs:line 37
at SAML2.Utils.Serialization.DeserializeFromXmlString[T](String xml) in src\SAML2\Utils\Serialization.cs:line 51
at SAML2.Saml20MetadataDocument..ctor(XmlDocument entityDescriptor) in src\SAML2\Saml20MetadataDocument.cs:line 91
at SAML2.Config.IdentityProviderCollection.ParseFile(String file) in src\SAML2\Config\IdentityProviderCollection.cs:line 358
at SAML2.Config.IdentityProviderCollection.Refresh() in src\SAML2\Config\IdentityProviderCollection.cs:line 161
at SAML2.Config.Saml2Config.Init(Saml2Config config) in src\SAML2\Config\Saml2Config.cs:line 143
at SAML2.Config.Saml2Config.InitFromConfigFile() in src\SAML2\Config\Saml2Config.cs:line 131
at SAML2.Config.Saml2Config.get_Current() in src\SAML2\Config\Saml2Config.cs:line 51
at SAML2.Logging.LoggerProvider..cctor() in src\SAML2\Logging\LoggerProvider.cs:line 26
Corresponding line from IdP (whole file is available at https://tnia.eidentita.cz/FPSTS/FederationMetadata/2007-06/FederationMetadata.xml):
<RoleDescriptor xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:fed="http://docs.oasis-open.org/wsfed/federation/200706" xsi:type="fed:SecurityTokenServiceType" [...]
If I should guess, reason why this element is present may be because this IdP claims to support both ws-federation and SAML2 and developers can choose which to implement. But they only provide one metadata file. The RoleDescriptor seems like it belongs to the other spec, and is useless for SAML 2.0 use case. This library has class with the same name, but
- it's an abstract class, it was never expected to encounter RoleDescriptor as raw element and the library doesn't use it directly (and if I fiddle with the IdP metadata and remove the xsi:type declaration, xml parser DOES throw because we are asking for an instance of an abstract class -> ignoring it shouldn't break any previously working uses)
- the content provided by NIA has very little overlap with the class structure (KeyDescriptor is present, but none of the fed: elements are)
I found two workarounds while investigating this, both horrible for general usage. I the end, all that is needed is this:
diff --git a/src/SAML2/Schema/Metadata/EntityDescriptor.cs b/src/SAML2/Schema/Metadata/EntityDescriptor.cs
index e03bb5b..31d542a 100644
--- a/src/SAML2/Schema/Metadata/EntityDescriptor.cs
+++ b/src/SAML2/Schema/Metadata/EntityDescriptor.cs
@@ -128,7 +128,6 @@ namespace SAML2.Schema.Metadata
[XmlElement(AuthnAuthorityDescriptor.ElementName, typeof(AuthnAuthorityDescriptor), Order = 3)]
[XmlElement(IdpSsoDescriptor.ElementName, typeof(IdpSsoDescriptor), Order = 3)]
[XmlElement(PdpDescriptor.ElementName, typeof(PdpDescriptor), Order = 3)]
- [XmlElement(RoleDescriptor.ElementName, typeof(RoleDescriptor), Order = 3)]
[XmlElement(SpSsoDescriptor.ElementName, typeof(SpSsoDescriptor), Order = 3)]
public object[] Items { get; set; }
Unknown element is silently skipped, and I can get as far as redirect to login endpoint on IdP with something that looks like valid assertion request (big base64-urlencoded string. I didn't yet go as far as trying to decode it back to XML. The request fails, but likely for unrelated reason).
Corresponding line from IdP (whole file is available at https://tnia.eidentita.cz/FPSTS/FederationMetadata/2007-06/FederationMetadata.xml):
If I should guess, reason why this element is present may be because this IdP claims to support both ws-federation and SAML2 and developers can choose which to implement. But they only provide one metadata file. The RoleDescriptor seems like it belongs to the other spec, and is useless for SAML 2.0 use case. This library has class with the same name, but
I found two workarounds while investigating this, both horrible for general usage. I the end, all that is needed is this:
Unknown element is silently skipped, and I can get as far as redirect to login endpoint on IdP with something that looks like valid assertion request (big base64-urlencoded string. I didn't yet go as far as trying to decode it back to XML. The request fails, but likely for unrelated reason).