问题
I have an MVC application (.Net Framework 4.5) which is been there for the last three years and using Forms Authentication mechanism. Now we want to integrate SSO feature with the help of Okta. Using KentorIT Authentication services I was able to integrate Okta with my mvc application. In that, all the configurations are being set in the web.config file (eg: entityId, signOnUrl etc.). Is there a way to programmatically configure these sso settings? I found that KentorAuthServicesSection is the class that we have to instantiate to do the process. Currently its reading the settings from configuration file.
public class KentorAuthServicesSection : ConfigurationSection
{
private static readonly KentorAuthServicesSection current =
(KentorAuthServicesSection)ConfigurationManager.GetSection("kentor.authServices");
}
So modifying this ConfigurationManager.GetSection("kentor.authServices") part with a custom implementation will do the job? or is there any other good approach ?
回答1:
You can just use the options classes directly -- no need to customize the GetSection
.
I'm assuming you are using the Mvc module. In which case you want to set the options on the AuthServicesController during application startup, e.g.
Kentor.AuthServices.Mvc.AuthServicesController.Options = myOptions;
With your own construction of these same configuration classes. For example:
var spOptions = new SPOptions
{
EntityId = new EntityId("http://localhost:57294/AuthServices"),
ReturnUrl = new Uri("http://localhost..."),
//...
};
options = new KentorAuthServicesAuthenticationOptions(false)
{
SPOptions = spOptions
};
The false
in this constructor tells it not to read from the configuration system.
There is a larger example in the OWIN sample project: https://github.com/KentorIT/authservices/blob/v0.21.1/SampleOwinApplication/App_Start/Startup.Auth.cs#L54-L82
来源:https://stackoverflow.com/questions/43980281/programatically-configure-sso-settings-using-kentor