0

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

MrEdmundo
  • 5,105
  • 13
  • 46
  • 58

1 Answers1

0

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

toadflakz
  • 7,764
  • 1
  • 27
  • 40
  • I probably should have mentioned this in my question, that's no good for us, we're largely configuring code which means the app.config is completely ignored. http://msdn.microsoft.com/en-us/library/hh205277(v=vs.110).aspx – MrEdmundo Sep 02 '14 at 14:35
  • Updated to show which methods you should use - which element you provide will be an interesting question tho' (unless there is always just one?) – toadflakz Sep 02 '14 at 14:46