Jia*_*nYA 1 asp.net .net-core asp.net-core identityserver4
我目前在IdentityServer 4指南的此页面上http://docs.identityserver.io/en/dev/quickstarts/3_interactive_login.html,并且我正在尝试启动MVC应用程序。
但是,当我启动客户端应用程序时,我一直收到此错误
InvalidOperationException: Unable to resolve service for type 'IdentityServer4.Services.IIdentityServerInteractionService' while attempting to activate 'IdentityServer4.Quickstart.UI.HomeController'.
Run Code Online (Sandbox Code Playgroud)
我进入了IdentityServer4 GitHub并从那里复制了代码,但是它根本没有运行。
我不确定如何从这里继续。
这是我的Startup.cs
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
namespace IdentityServerClient
{
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();
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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果您使用的是快速入门用户界面,则应使用以下指南:
https://github.com/IdentityServer/IdentityServer4.Quickstart.UI
引用该页面:
接下来,您需要配置身份验证处理程序:
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
// some details omitted
services.AddIdentityServer();
services.AddAuthentication()
...
Run Code Online (Sandbox Code Playgroud)
您不见了:
services.AddIdentityServer()
.AddInMemoryCaching()
.AddClientStore<InMemoryClientStore>()
.AddResourceStore<InMemoryResourcesStore>(); // <-- Add this
Run Code Online (Sandbox Code Playgroud)
结果,没有任何身份服务器服务注册到依赖项注入容器,这就是为什么您看到该错误的原因。
您链接到的教程文档似乎已过期。
-
这是要遵循的完整步骤集:
现在将您修改Startup.cs
为如下所示:
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
}); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddIdentityServer()
.AddInMemoryCaching()
.AddClientStore<InMemoryClientStore>()
.AddResourceStore<InMemoryResourcesStore>();
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1748 次 |
最近记录: |