GCN-B-66b217e55cd6

GCN-G-66b217e55cd6: Failed to start GoCloudNative.BFF. Registering multiple identity providers of the same type is not supported.

The GoCloudNative.Authentication.BFF was designed with extensibility in mind. We offer standard implementations for common identity providers. But we also want to allow integration with other identity providers.

Integrating with identity providers is done by implementing the IIdentityProvider interface and registring it like so:

var builder = WebApplication.CreateBuilder(args);

var config = builder.Configuration
    .GetSection("Oidc")
    .Get<OpenIdConnectConfig>();

builder.Services.AddSecurityBff(o =>
{
    o.RegisterIdentityProvider<OpenIdConnectIdentityProvider, OpenIdConnectConfig>(config);
}

A shorthand for this is:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddSecurityBff(o =>
{
    o.ConfigureOpenIdConnect(builder.Configuration.GetSection("Oidc"));
}

How to reproduce the error

What causes this error is the fact that the same type of identityprovider is being configured more than once. Like so, for example:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddSecurityBff(o =>
{
    o.ConfigureOpenIdConnect(builder.Configuration.GetSection("Idp1"));
    o.ConfigureOpenIdConnect(builder.Configuration.GetSection("Idp2")); // this line raises the error
}

Solution

Registering the same type of identity provider multiple times is not supported yet. If you need this feature, please create an issue here.

To resolve the error, remove one of the registrations:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddSecurityBff(o =>
{
    o.ConfigureOpenIdConnect(builder.Configuration.GetSection("Idp1"));
    // ~~o.ConfigureOpenIdConnect(builder.Configuration.GetSection("Idp2"));~~ remove this line
}