Unable to resolve service for type 'Duende.IdentityServer.Stores.IClientStore'

2.9k views Asked by At

I am migrating drom Identity Server to Duende Identity Server and using .net 6 core project and I'm getting the following error in the startup on builder.build().

InvalidOperationException: Unable to resolve service for type 'Duende.IdentityServer.Stores.IClientStore' while attempting to activate 'Duende.IdentityServer.Validation.AuthorizeRequestValidator'

Here is my startup code:


// add configuration mappings
builder.Services.AddOptions();
builder.Services.Configure<MaximizerConfiguration>(builder.Configuration.GetSection(MaximizerConfiguration.CONFIG_SECTION));
builder.Services.Configure<MessageEmailConfiguration>(builder.Configuration.GetSection(MessageEmailConfiguration.CONFIG_SECTION));
builder.Services.Configure<SitefinityLinksConfiguration>(builder.Configuration.GetSection(SitefinityLinksConfiguration.CONFIG_SECTION));
builder.Services.Configure<OIDCClientsConfiguration>(builder.Configuration.GetSection(OIDCClientsConfiguration.CONFIG_SECTION));

// database context with asp.net identity
builder.Services.AddDbContext<IdentityContext>(options =>
{
    options.UseSqlServer(builder.Configuration.GetConnectionString(IdentityContext.CONNECTION_NAME));

});

builder.Services.AddIdentity<User, IdentityRole>(options =>
{
    options.SignIn.RequireConfirmedEmail = true;

    options.Lockout.MaxFailedAccessAttempts = 10;
    options.Lockout.DefaultLockoutTimeSpan = new TimeSpan(0, 15, 0);

    options.Password.RequireDigit = true;
    options.Password.RequiredLength = 8;
    options.Password.RequireLowercase = true;
    options.Password.RequireUppercase = true;
    options.Password.RequireNonAlphanumeric = false;
})
    .AddEntityFrameworkStores<IdentityContext>()
    .AddUserManager<UserManager>()
    .AddDefaultTokenProviders();


builder.Services.AddMvc();


builder.Services.AddIdentityServer()
                .AddDeveloperSigningCredential()
                .AddAspNetIdentity<User>()
                .AddProfileService<ProfileManager>();

var tokenExp = double.Parse(builder.Configuration["TokenExpirationInHours"]);
builder.Services.Configure<DataProtectionTokenProviderOptions>(o => o.TokenLifespan = TimeSpan.FromHours(tokenExp));

// custom services
builder.Services.AddTransient<MessageContext>();
builder.Services.AddTransient<MaximizerContext>();
builder.Services.AddTransient<ProfileManager>();
builder.Services.AddTransient<EmailManager>();

builder.Services.AddSingleton<IConfiguration>(builder.Configuration);
// Add services to the container.
builder.Services.AddControllersWithViews();

var app = builder.Build();```
1

There are 1 answers

1
David Andrews On

I figured out the problem. IClientStore is needed so to resolve it I just added these lines in the startup.

.AddInMemoryIdentityResources(IdentityConfiguration.GetIdentityResources()) .AddInMemoryClients(IdentityConfiguration.GetClients(builder.Configuration))