Forums, Documentation & Knowledge Base - ComponentSpace

Deserialization issue


https://componentspace.com/forums/Topic11267.aspx

By [email protected] - 11/13/2020

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)

<snipped other service configurations>

    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<SamlConfigurations>(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? 
By ComponentSpace - 11/13/2020

No Worries. Thanks Martin.