【发布时间】:2018-04-23 13:17:42
【问题描述】:
我正在.net core 2 中使用 IdentityServer 4 实现身份验证服务器并对其进行测试,我使用了本教程 http://docs.identityserver.io/en/release/quickstarts/3_interactive_login.html 实现 MVC 客户端,但它向我显示此错误:
InvalidOperationException:尝试激活“IdentityServer4.Validation.AuthorizeRequestValidator”时无法解析“IdentityServer4.Stores.IClientStore”类型的服务。
我尝试了很多东西,但都没有奏效。
谢谢
这是客户端 MVC 端:
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;
});
}
这是我的启动 IdentityServer 端:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddInMemoryApiResources(Config.GetApiResources())
.AddInMemoryIdentityResources(Config.GetIdentityResources())
.AddInMemoryClients(Config.GetClients())
.AddTestUsers(Config.GetUsers());
}
namespace ClientMVC
{ 公共类启动 { 公共启动(IConfiguration 配置) { 配置=配置; }
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
{ 公共类启动 { // 这个方法被运行时调用。使用此方法向容器添加服务。 // 有关如何配置应用程序的更多信息,请访问https://go.microsoft.com/fwlink/?LinkID=398940 公共无效配置服务(IServiceCollection 服务) { 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();
}
}
}
【问题讨论】:
-
添加您的 startup.cs,尤其是您配置 IdentityServer 的位置。
-
我在@RuardvanElburg 的帖子中添加了它
-
嗨,这个问题为你解决了吗
标签: .net asp.net-mvc dependency-injection identityserver4 .net-core-2.0