authentication - 带有 IAuthenticationSchemeProvider 的 IdentityServer4 的动态方案 SAML 2.0
问题描述
我正在尝试将 IdentityServer4 设置为与多个外部 IdP 一起使用,这些 IdP 是在IAuthenticationSchemeProvider
'sAddScheme
方法的帮助下动态添加的。
我已经成功地为OpenIdConnect
IdP 完成了它,但是在使用Saml2p
基于 IdP 时遇到了一些麻烦。在这个示例之后,我对 Saml2p 遵循了相同的逻辑:
注入IOptionsMonitorCache<Saml2pAuthenticationOptions>
和:
if (await _schemeProvider.GetSchemeAsync(scheme) == null)
{
_schemeProvider.AddScheme(new AuthenticationScheme(scheme, scheme, typeof(Saml2pAuthenticationHandler)));
}
else
{
_saml2pOptionsCache.TryRemove(scheme);
}
_saml2pOptionsCache.TryAdd(scheme, samlOptions);
我遇到了一个例外:
Unable to resolve service for type 'Rsk.AspNetCore.Authentication.Saml2p.Factories.ISamlFactory``1[IdentityServer4.Saml.Generators.Interfaces.IServiceProviderMetadataGenerator]' while attempting to activate 'Rsk.AspNetCore.Authentication.Saml2p.Saml2pAuthenticationHandler'.
我不确定在添加方案时是否应该设置一些关于 Saml 的额外配置,任何帮助表示赞赏。
编辑:我将 Rsk NuGet 用于 SAML 2.0
解决方案
对AddSaml2p
注册依赖加载以及身份验证处理程序的调用。
我要么AddSaml2p
在你的代码中调用某个地方,要么自己注册所需的依赖项,如下所示:
builder.Services.AddMemoryCache();
builder.Services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
builder.Services.TryAddScoped<ISamlFactory<IServiceProviderMetadataGenerator>,
builder.Services.TryAddScoped<ISamlFactory<ISaml2SingleSignOnRequestGenerator>, Saml2SingleSignOnRequestGeneratorFactory>();
builder.Services.TryAddScoped<ISamlFactory<ISaml2SingleLogoutRequestGenerator>, Saml2SingleLogoutRequestGeneratorFactory>();
builder.Services.TryAddScoped<ISamlFactory<ISaml2SingleSignOnResponseValidator>, Saml2SingleSignOnResponseValidatorFactory>();
builder.Services.TryAddScoped<ISamlBindingService, SamlBindingService>();
builder.Services.TryAddScoped<ISamlSigningService, SamlSigningService>();
builder.Services.TryAddScoped<IDateTimeService, SystemClockDateTimeService>();
builder.Services.TryAddScoped<ISamlTimeComparer, SamlTimeComparer>();
builder.Services.TryAddScoped<ISamlCorrelationStore, CookieCorrelationStore>();
推荐阅读
- reactjs - formik如何填写initialValue?
- swiftui - SwiftUI PreviewDevice 没有设置 userInterfaceIdiom — 如何设置 userInterfaceIdiom 进行预览?
- javascript - 如何在 getInitialProps 中使用 Apollo 客户端?- 下一个 9.3.5
- python - 无法在 Vscode 编辑器上导入熊猫
- bitrix - 如何在 britix24 菜单中为某些用户隐藏日历、聊天和通话等项目?
- shell - 从命名管道中分离而不终止源程序
- c++ - 无法编译 C++ deque.erase() 调用
- android - 寻呼机应用程序 - 当应用程序被杀死时 - 监听 firebase 更改并发送通知
- excel - 禁用 F1(帮助按钮)
- svelte - 在 Svelte 组件中导入 Typescript 模块