Set up Sustainsys.Saml2 configuration in Web.config programmatically

528 views Asked by At

I'm trying to set up Sustainsys' Saml2 integration in an ASP.NET MVC 4 application. However, I need the identity provider options (such as Entity ID, sign-on URL, logout URL, signing certificate, service certificate and federation metadata) to be sourced from a UI I'm also writing. That means these options need to be edited on the fly. I've read into the component's documentation, however I don't see any way to programmatically set these options, except with Owin (which unfortunately won't work for my case).

I tried manually creating configuration sections using Sustainsys' own classes, however much of the properties are either protected or outright lack setters.

I also tried creating my own configuration sections which would override Sustainsys' ones, but during runtime the XML sections always get deserialized into Sustainsys' classes.

I could always edit the Web.config as a plain XML file, but I feel this would not be an elegant solution.

Is there any way to set (and subsequently change) the <sustainsys.saml2> tag and everything in it programmatically?

1

There are 1 answers

0
Anders Abel On

The Sustainsys Saml2 options are global for both the HttpModule and the Mvc package. The web.config entries are mapped over to the real options class once, so if you need to work with them programmatically there's no need to go through the web.config configuration classes, instead access the options directly:

For HttpModule: Sustainsys.Saml2.HttpModule.Saml2AuthenticationModule.Options

For Mvc package: Sustainsys.Saml2.Mvc.Saml2Controller.Options