身份服务器多个提供者

kos*_*kov 5 c# identityserver4

嗨,我正在尝试添加多个提供商

public static AuthenticationBuilder AddIdentityProviders(this AuthenticationBuilder builder, IConfiguration configuration)
{
    var identityProvidersOptions = configuration.GetSection(identityProvidersSectionName)
                                                .Get<IdentityProviderOptions[]>();

    var ipFactory = new IdentityProviderControlFactory();

    foreach (var identityProvider in identityProvidersOptions)
    {
        if ( Enum.TryParse(identityProvider.Discriminator, out IdentityProviderTypes accessControlType) 
            && accessControlType != IdentityProviderTypes.None )
        {
            builder = ipFactory.GetIdentityProviderService(accessControlType)
                                .Register(builder, configuration, identityProvider);
        }
        else
        {
            throw new NotImplementedException();
        }
    }

    return builder;
}
Run Code Online (Sandbox Code Playgroud)

在设置中,我有两个提供者,然后为每个“注册”方法启动:

AuthenticationBuilder Register(AuthenticationBuilder builder, IConfiguration configuration, IdentityProviderOptions identityProviderOptions)
Run Code Online (Sandbox Code Playgroud)

里面创建了一个这样的单例:

builder.Services.AddSingleton<IConfigureOptions<OpenIdConnectOptions>, ConfigureAzureOptions>();
builder.AddOpenIdConnect(identityProviderOptions.Name, identityProviderOptions.Name, _ => { });
Run Code Online (Sandbox Code Playgroud)

就在几秒钟之内

builder.Services.AddSingleton<IConfigureOptions<OpenIdConnectOptions>, ConfigureIBMOptions>();
builder.AddOpenIdConnect(identityProviderOptions.Name, identityProviderOptions.Name, _ => { });
Run Code Online (Sandbox Code Playgroud)

似乎这是一个问题,因为似乎只能注册一个提供者,而几秒钟只能覆盖一些值,那么如何为身份服务器注册多个提供者?

如果我添加两个 identityProviders 我得到异常

System.Security.Cryptography.CryptographicException: 'The payload was invalid.' 
Run Code Online (Sandbox Code Playgroud)

kos*_*kov 1

我知道这与 CallbackPath 和 SignedOutCallbackPath 相关,因为每个提供程序都必须不同,我现在正在寻找一种方法来覆盖这些端点。

“您将在目标身份提供商中将特定的 CallbackPath 和 SignedOutCallbackPath 配置为允许的站点。因此,当目标身份提供商回发时,它将回发到您在 CallbackPath 中配置的路由,并且 Oidc 中间件将为您选择正确的配置”