0
votes

I have a config file with IdentityConfiguration information in it which I am using for securing my WCF Services e.g.

<system.identityModel>
    <identityConfiguration>
      <securityTokenHandlers>
        <securityTokenHandlerConfiguration>
          <issuerNameRegistry type="System.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <trustedIssuers>
              <add thumbprint="4459.....5E4" name="adfs" />
              <add thumbprint="85BBD0....94A4C7" name="identityServer" />
            </trustedIssuers>
          </issuerNameRegistry>
        </securityTokenHandlerConfiguration>
      </securityTokenHandlers>
      <audienceUris>
        <add value="https://Iamauri/services"/>
      </audienceUris>
    </identityConfiguration>
  </system.identityModel>

I would like to deserialize the above in to an IdentityConfiguration object but I can't figure out how to go from a ConfigurationSection representing the above information to a concrete type.

What I have so far:

var config = ConfigurationManager.OpenMappedExeConfiguration( new ExeConfigurationFileMap() { ExeConfigFilename = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile }, ConfigurationUserLevel.None);

var s = (SystemIdentityModelSection) config.GetSection("system.identityModel");

// TODO: Deserialize s to IdentityConfiguration

1

1 Answers

0
votes

If you have that configuration in your app.config file, the correct handler for the configuration section will be automatically used so you shouldn't have to do anything beyond calling IdentityConfiguration.LoadConfiguration() which should return the object you are looking for.

More info at: System.IdentityModel.Configuration.IdentityConfiguration.LoadConfiguration

Edit after comment:

If you are manually working with the SystemIdentityModelSection object, you can use the IdentityConfigurationElements contained in this object to load an IdentityConfiguration by calling IdentityConfiguration.LoadHandlerConfiguration().

More info on this method at: System.IdentityModel.Configuration.IdentityConfiguration.LoadHandlerConfiguration