Asp.net core 使用Sustainsys-SAML2和ASP.net核心动态加载SAML2 IDP

Asp.net core 使用Sustainsys-SAML2和ASP.net核心动态加载SAML2 IDP,asp.net-core,sustainsys-saml2,Asp.net Core,Sustainsys Saml2,在ASP.net核心web应用程序启动后,动态加载SAML2 IDP的最佳方式是什么 到目前为止,我能够使用以下代码在运行时动态添加SAML2 IDP: //DI in Constructor public ClassName(IAuthenticationSchemeProvider schemeProvider, IOptionsMonitorCache<Saml2Options> optionsCache) { _schemeProvider = scheme

在ASP.net核心web应用程序启动后,动态加载SAML2 IDP的最佳方式是什么

到目前为止,我能够使用以下代码在运行时动态添加SAML2 IDP:

//DI in Constructor 
public ClassName(IAuthenticationSchemeProvider schemeProvider,
    IOptionsMonitorCache<Saml2Options> optionsCache)
{
    _schemeProvider = schemeProvider;
    _optionsCache = optionsCache;
}

public async Task LoadIDP()
{
    ...
    _schemeProvider.AddScheme(new AuthenticationScheme(schemeName, schemeName,typeof(Saml2Handler)));

    _optionsCache.TryAdd(schemeName, new Saml2Options(){...});
}
//构造函数中的DI
公共类名(IAAuthenticationSchemeProvider schemeProvider,
IOptionsMonitorCache选项缓存)
{
_schemeProvider=schemeProvider;
_选项缓存=选项缓存;
}
公共异步任务LoadIDP()
{
...
_AddScheme(新的AuthenticationScheme(schemeName,schemeName,typeof(Saml2Handler));
_optionCache.TryAdd(schemeName,新的Saml2Options(){…});
}
这是可行的,但当有多个应用程序实例在负载平衡环境中运行时,我仍在努力进行动态加载


是否可以在每次有人试图使用SAML2登录时查询数据库以加载配置?

是的,使用
GetIdentityProvider
SelectIdentityProvider
通知。通过实现它们,您可以完全绕过内存中的集合。请注意,缓存IdentityProvider对象是一个好主意,特别是如果您让它们加载元数据,或者最终会在每次请求时重新加载Idp元数据。

是,使用
GetIdentityProvider
选择IdentityProvider
通知。通过实现它们,您可以完全绕过内存中的集合。请注意,缓存IdentityProvider对象是一个好主意,特别是如果您让它们加载元数据,或者最终会在每个请求上重新加载Idp元数据