首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >动态方案SAML2.0 for IdentityServer4 with IAuthenticationSchemeProvider

动态方案SAML2.0 for IdentityServer4 with IAuthenticationSchemeProvider
EN

Stack Overflow用户
提问于 2019-04-12 06:48:18
回答 1查看 358关注 0票数 1

我正在尝试将IdentityServer4设置为使用多个外部IdP,这些IdP是在IAuthenticationSchemeProviderAddScheme方法的帮助下动态添加的。

我已经成功地为OpenIdConnect IdP完成了这项工作,但在基于Saml2p的IdP上遇到了一些问题。在this示例中,我遵循了Saml2p的相同逻辑:

注入的IOptionsMonitorCache<Saml2pAuthenticationOptions>和:

代码语言:javascript
复制
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的额外配置,感谢任何帮助。

编辑:我正在为SAML2.0使用Rsk NuGet

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-12 17:40:58

AddSaml2p的调用注册了大量依赖项和身份验证处理程序。

我会在代码中的某个地方调用AddSaml2p,或者自己注册所需的依赖项,如下所示:

代码语言:javascript
复制
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>();
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55642222

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档