没有为方案配置身份验证处理程序:idsrv
No authentication handler is configured for the scheme: idsrv
我是 .net 核心世界的新手,正在尝试设置身份服务器。我遵循了 https://identityserver4.readthedocs.io/en/release/quickstarts/6_aspnet_identity.html 的指南,并设法让基础知识发挥作用。我现在想将 .Net core Identity 与 identityServer 结合使用,但它给出了一个我不知道如何解决的异常。异常:
没有身份验证处理程序配置为对该方案进行身份验证:idsrv
Executed action IdentityServer4.Quickstart.UI.GrantsController.Index (IdentityServer) in 22.9784ms
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[0]
An unhandled exception has occurred while executing the request
System.InvalidOperationException: No authentication handler is configured to authenticate for the scheme: idsrv
at Microsoft.AspNetCore.Http.Authentication.Internal.DefaultAuthenticationManager.<GetAuthenticateInfoAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
我曾尝试浏览 github 问题以了解类似问题,有人说这与 IdentityServer 和 Identity 的加载顺序有关。但就我而言,它们应该是正确的?
我的Startup.csclass:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<IdentityUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc();
// Adds IdentityServer
services.AddIdentityServer()
.AddTemporarySigningCredential()
.AddInMemoryIdentityResources(Resources.GetIdentityResources())
.AddInMemoryApiResources(Resources.GetApiResources())
.AddInMemoryClients(Clients.Get())
.AddAspNetIdentity<IdentityUser>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseIdentity();
// Adds IdentityServer
app.UseIdentityServer();
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
}
您还需要在 Configure() 方法中设置 cookie 中间件。
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = AuthenticationSchemeConstants.DefaultCookieAuthenticationScheme,
CookieName = $"{AuthenticationSchemeConstants.CookiePrefixName}.auth",
ExpireTimeSpan = TimeSpan.FromMinutes(20),
SlidingExpiration = true,
AutomaticAuthenticate = false,
AutomaticChallenge = false
});
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = AuthenticationSchemeConstants.ExternalCookieAuthenticationScheme,
AutomaticAuthenticate = false,
AutomaticChallenge = false
});
app.UseIdentityServer();
https://identityserver4.readthedocs.io/en/release/topics/signin_external_providers.html
https://github.com/IdentityServer/IdentityServer4/issues/1058
希望对您有所帮助
尝试将此添加到您的 Configure()
方法中:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = "idsrv", // Matches the name it's looking for in the exception
AutomaticAuthenticate = true,
AutomaticChallenge = true
});
in .NET core 2.0
ProviderAuthenticationOptions class 不再定义 AuthenticationScheme
属性.
In 1.x, the AutomaticAuthenticate and AutomaticChallenge properties were intended to be set on a single authentication scheme
In 2.0, these two properties have been removed as flags on the individual AuthenticationOptions instance and have moved into the base AuthenticationOptions class. The properties can be configured in the AddAuthentication method call within the ConfigureServices method of Startup.cs:
authenticationScheme
应在调用 UseProvider 身份验证方法时配置 在 ConfigureServices 方法中
services
.AddAuthentication(opts =>{
opts.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie("idsrv", opts =>
{
//AuthenticationScheme = "idsrv",
//AutomaticAuthenticate = true,
//AutomaticChallenge = true
})
我是 .net 核心世界的新手,正在尝试设置身份服务器。我遵循了 https://identityserver4.readthedocs.io/en/release/quickstarts/6_aspnet_identity.html 的指南,并设法让基础知识发挥作用。我现在想将 .Net core Identity 与 identityServer 结合使用,但它给出了一个我不知道如何解决的异常。异常:
没有身份验证处理程序配置为对该方案进行身份验证:idsrv
Executed action IdentityServer4.Quickstart.UI.GrantsController.Index (IdentityServer) in 22.9784ms
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[0]
An unhandled exception has occurred while executing the request
System.InvalidOperationException: No authentication handler is configured to authenticate for the scheme: idsrv
at Microsoft.AspNetCore.Http.Authentication.Internal.DefaultAuthenticationManager.<GetAuthenticateInfoAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
我曾尝试浏览 github 问题以了解类似问题,有人说这与 IdentityServer 和 Identity 的加载顺序有关。但就我而言,它们应该是正确的?
我的Startup.csclass:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<IdentityUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc();
// Adds IdentityServer
services.AddIdentityServer()
.AddTemporarySigningCredential()
.AddInMemoryIdentityResources(Resources.GetIdentityResources())
.AddInMemoryApiResources(Resources.GetApiResources())
.AddInMemoryClients(Clients.Get())
.AddAspNetIdentity<IdentityUser>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseIdentity();
// Adds IdentityServer
app.UseIdentityServer();
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
}
您还需要在 Configure() 方法中设置 cookie 中间件。
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = AuthenticationSchemeConstants.DefaultCookieAuthenticationScheme,
CookieName = $"{AuthenticationSchemeConstants.CookiePrefixName}.auth",
ExpireTimeSpan = TimeSpan.FromMinutes(20),
SlidingExpiration = true,
AutomaticAuthenticate = false,
AutomaticChallenge = false
});
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = AuthenticationSchemeConstants.ExternalCookieAuthenticationScheme,
AutomaticAuthenticate = false,
AutomaticChallenge = false
});
app.UseIdentityServer();
https://identityserver4.readthedocs.io/en/release/topics/signin_external_providers.html https://github.com/IdentityServer/IdentityServer4/issues/1058
希望对您有所帮助
尝试将此添加到您的 Configure()
方法中:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = "idsrv", // Matches the name it's looking for in the exception
AutomaticAuthenticate = true,
AutomaticChallenge = true
});
in .NET core 2.0
ProviderAuthenticationOptions class 不再定义 AuthenticationScheme
属性.
In 1.x, the AutomaticAuthenticate and AutomaticChallenge properties were intended to be set on a single authentication scheme
In 2.0, these two properties have been removed as flags on the individual AuthenticationOptions instance and have moved into the base AuthenticationOptions class. The properties can be configured in the AddAuthentication method call within the ConfigureServices method of Startup.cs:
authenticationScheme
应在调用 UseProvider 身份验证方法时配置 在 ConfigureServices 方法中
services
.AddAuthentication(opts =>{
opts.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie("idsrv", opts =>
{
//AuthenticationScheme = "idsrv",
//AutomaticAuthenticate = true,
//AutomaticChallenge = true
})