1

我有一个 MVC 应用程序(.Net Framework 4.5),它在过去三年中一直存在并使用表单身份验证机制。现在我们想在 Okta 的帮助下集成 SSO 功能。使用 KentorIT 身份验证服务,我能够将 Okta 与我的 mvc 应用程序集成。其中,所有配置都在 web.config 文件中设置(例如:entityId、signOnUrl 等)。有没有办法以编程方式配置这些 sso 设置?我发现 KentorAuthServicesSection 是我们必须实例化以执行该过程的类。目前它从配置文件中读取设置。

 public class KentorAuthServicesSection : ConfigurationSection
 {
        private static readonly KentorAuthServicesSection current =
            (KentorAuthServicesSection)ConfigurationManager.GetSection("kentor.authServices");
 }

那么用自定义实现修改这个 ConfigurationManager.GetSection("kentor.authServices") 部分就可以了?还是有其他好的方法?

4

1 回答 1

1

您可以直接使用选项类——无需自定义GetSection.

我假设您正在使用 Mvc 模块。在这种情况下,您想在应用程序启动期间设置 AuthServicesController 上的选项,例如

Kentor.AuthServices.Mvc.AuthServicesController.Options = myOptions;

使用您自己构建这些相同的配置类。例如:

var spOptions = new SPOptions
{
    EntityId = new EntityId("http://localhost:57294/AuthServices"),
    ReturnUrl = new Uri("http://localhost..."),
    //...
};
options = new KentorAuthServicesAuthenticationOptions(false)
{
   SPOptions = spOptions
};

false构造函数中的 告诉它不要从配置系统中读取。

OWIN示例项目中有一个更大的示例: https ://github.com/KentorIT/authservices/blob/v0.21.1/SampleOwinApplication/App_Start/Startup.Auth.cs#L54-L82

于 2017-05-15T13:49:59.837 回答