0
votes

I am implementing an authentication Server with IdentityServer 4 in .net core 2 and to test it I have used this tutorial http://docs.identityserver.io/en/release/quickstarts/3_interactive_login.html to implement an MVC client but it shows me this error:

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

I've tried a lot of things but none of them worked.

Thank you

This is Client MVC Side:

 public void ConfigureServices(IServiceCollection services)
 {
        services.AddIdentityServer();

        services.AddMvc();

        JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

        services.AddAuthentication(options =>
        {
            options.DefaultScheme = "Cookies";
            options.DefaultChallengeScheme = "oidc";
        })
            .AddCookie("Cookies")
            .AddOpenIdConnect("oidc", options =>
            {
                options.SignInScheme = "Cookies";
                options.Authority = "http://localhost:5000";
                options.RequireHttpsMetadata = false;

                options.ClientId = "mvc";
                options.SaveTokens = true;
            });
}

This is my startUp IdentityServer Side:

public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();

        services.AddIdentityServer()
                 .AddDeveloperSigningCredential()
                 .AddInMemoryApiResources(Config.GetApiResources())
                 .AddInMemoryIdentityResources(Config.GetIdentityResources())
                 .AddInMemoryClients(Config.GetClients())
                 .AddTestUsers(Config.GetUsers());

    }
namespace ClientMVC

{ public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {

        services.AddMvc();

        JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

        services.AddAuthentication(options =>
        {
            options.DefaultScheme = "Cookies";
            options.DefaultChallengeScheme = "oidc";
        })
            .AddCookie("Cookies")
            .AddOpenIdConnect("oidc", options =>
            {
                options.SignInScheme = "Cookies";

                options.Authority = "http://localhost:5000";
                options.RequireHttpsMetadata = false;

                options.ClientId = "mvc";
                options.SaveTokens = true;
            });




    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
        }
        app.UseAuthentication();

        app.UseStaticFiles();
        app.UseMvcWithDefaultRoute();
    }
}

}

namespace Server

{ public class Startup { // This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddMvc();

        services.AddIdentityServer()
                 .AddDeveloperSigningCredential()
                 .AddInMemoryApiResources(Config.GetApiResources())
                 .AddInMemoryIdentityResources(Config.GetIdentityResources())
                 .AddInMemoryClients(Config.GetClients())
                 .AddTestUsers(Config.GetUsers());

    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    { 
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseIdentityServer();
        app.UseStaticFiles();
        app.UseMvcWithDefaultRoute();

    }
}

}

1
Add your startup.cs, in particular where you configure IdentityServer.Ruard van Elburg
I added it in the post @RuardvanElburgaous elkadhi
Hi was this issue solved for youJianYA

1 Answers

1
votes

In your MVC client configuration, that you have provided, remove:

services.AddIdentityServer();

This should exist only in the startup of the Identity Server project. services.AddAuthentication(options =>... is the piece of code, that tells the MVC app, that it is protected by something, and further on, the AddOpenIdConnect specifies that this is your IdentityServer.

EDIT

In general all the services that you are using and injecting in your controllers, should be initially added in the public void ConfigureServices(IServiceCollection services).

For example, if you have an 'IUserService' you need to add it to the IServiceCollection object. Like this:

services.AddTransient<IUserService, UserService>();