Deserialization issue

I’m having issues deserializing a saml.json file, the error is:

Document

NameValueType
$exception{“The SAML configuration couldn’t be deserialized.”}ComponentSpace.Saml2.Exceptions.SamlException

Document
NameValueType
InnerException{“Object reference not set to an instance of an object.”}System.Exception {System.NullReferenceException}

The code I’m running is:

public void ConfigureServices(IServiceCollection services)



string jsonConfigName = “saml-simple.json”;
string samlConfigPath = @“C:\Projects\SamlTest”;

string jsonFilePath = System.IO.Path.Combine(samlConfigPath, jsonConfigName);
string samlConfigText = System.IO.File.ReadAllText(jsonFilePath);

var configurations = Newtonsoft.Json.JsonConvert.DeserializeObject(samlConfigText);

// Always fails.
services.AddSaml(samlConfigurations =>
{
samlConfigurations.Configurations = ConfigurationDeserializer.Deserialize(jsonConfigName, samlConfigPath).Configurations;
});

// Works
services.AddSaml(samlConfigurations =>
{
samlConfigurations.Configurations = configurations.Configurations;
});

… and the JSON contents of the file is:

{
“$schema”: “<a href=“https://www.componentspace.com/schemas/saml-config-schema-v1.0.json",">https://www.componentspace.com/schemas/saml-config-schema-v1.0.json”,
“Configurations”: [
{
“ID”: “test1”,
“LocalServiceProviderConfiguration”: {
“Name”: “<a href=“https://ExampleServiceProvider”,”>https://ExampleServiceProvider”,
“Description”: “Example Service Provider”,
“AssertionConsumerServiceUrl”: "<a href=“https://localhost:44360/SAML/AssertionConsumerService",">https://localhost:44360/SAML/AssertionConsumerService”,
“SingleLogoutServiceUrl”: "<a href=“https://localhost:44360/SAML/SingleLogoutService",">https://localhost:44360/SAML/SingleLogoutService”,
“ArtifactResolutionServiceUrl”: “<a href=“https://localhost:44360/SAML/ArtifactResolutionService",">https://localhost:44360/SAML/ArtifactResolutionService”,
“LocalCertificates”: [
{
“FileName”: “certificates/sp.pfx”,
“Password”: “password”
}
]
},
“PartnerIdentityProviderConfigurations”: [
{
“Name”: “<a href=“https://ExampleIdentityProvider”,”>https://ExampleIdentityProvider”,
“Description”: “Example Identity Provider”,
“SignAuthnRequest”: true,
“SignLogoutRequest”: true,
“SignLogoutResponse”: true,
“WantLogoutRequestSigned”: true,
“WantLogoutResponseSigned”: true,
“SingleSignOnServiceUrl”: "<a href=“https://localhost:44313/SAML/SingleSignOnService",">https://localhost:44313/SAML/SingleSignOnService”,
“SingleLogoutServiceUrl”: "<a href=“https://localhost:44313/SAML/SingleLogoutService",">https://localhost:44313/SAML/SingleLogoutService”,
“ArtifactResolutionServiceUrl”: "<a href=“https://localhost:44313/SAML/ArtifactResolutionService",">https://localhost:44313/SAML/ArtifactResolutionService”,
“PartnerCertificates”: [
{
“FileName”: “certificates/idp.cer”
}
]
}
]
}
]
}

As you can see, this isn’t a big problem now, because I used the Newtonsoft library directly, but it would be best to use the supplied method for deserialisation.

Am I missing some additional configuration settings?

[quote]
I'm having issues deserializing a saml.json file, the error is:

Document
NameValueType
$exception{"The SAML configuration couldn't be deserialized."}ComponentSpace.Saml2.Exceptions.SamlException

Document
NameValueType
InnerException{"Object reference not set to an instance of an object."}System.Exception {System.NullReferenceException}

The code I'm running is:

public void ConfigureServices(IServiceCollection services)



string jsonConfigName = "saml-simple.json";
string samlConfigPath = @"C:\Projects\SamlTest";

string jsonFilePath = System.IO.Path.Combine(samlConfigPath, jsonConfigName);
string samlConfigText = System.IO.File.ReadAllText(jsonFilePath);

var configurations = Newtonsoft.Json.JsonConvert.DeserializeObject(samlConfigText);

// Always fails.
services.AddSaml(samlConfigurations =>
{
samlConfigurations.Configurations = ConfigurationDeserializer.Deserialize(jsonConfigName, samlConfigPath).Configurations;
});

// Works
services.AddSaml(samlConfigurations =>
{
samlConfigurations.Configurations = configurations.Configurations;
});

... and the JSON contents of the file is:

{
"$schema": "https://www.componentspace.com/schemas/saml-config-schema-v1.0.json",
"Configurations": [
{
"ID": "test1",
"LocalServiceProviderConfiguration": {
"Name": "https://ExampleServiceProvider",
"Description": "Example Service Provider",
"AssertionConsumerServiceUrl": "https://localhost:44360/SAML/AssertionConsumerService",
"SingleLogoutServiceUrl": "https://localhost:44360/SAML/SingleLogoutService",
"ArtifactResolutionServiceUrl": "https://localhost:44360/SAML/ArtifactResolutionService",
"LocalCertificates": [
{
"FileName": "certificates/sp.pfx",
"Password": "password"
}
]
},
"PartnerIdentityProviderConfigurations": [
{
"Name": "https://ExampleIdentityProvider",
"Description": "Example Identity Provider",
"SignAuthnRequest": true,
"SignLogoutRequest": true,
"SignLogoutResponse": true,
"WantLogoutRequestSigned": true,
"WantLogoutResponseSigned": true,
"SingleSignOnServiceUrl": "https://localhost:44313/SAML/SingleSignOnService",
"SingleLogoutServiceUrl": "https://localhost:44313/SAML/SingleLogoutService",
"ArtifactResolutionServiceUrl": "https://localhost:44313/SAML/ArtifactResolutionService",
"PartnerCertificates": [
{
"FileName": "certificates/idp.cer"
}
]
}
]
}
]
}

As you can see, this isn't a big problem now, because I used the Newtonsoft library directly, but it would be best to use the supplied method for deserialisation.

Am I missing some additional configuration settings?
[/quote]

Sorry to answer my own question, I realise now the jsonPath is "The JSON path expression identifying the location of the SAML configuration in the file." as per the instructions!

No Worries. Thanks Martin.