C# 使用授权配置IdentityServerJwt身份验证
我有一个Blazor webassembly应用程序,它使用IdentityServerJwt AddAuthentication,并且正在使用Hangfire。我正试图将Hangfire配置为只允许管理员用户根据文章进行授权,但我得到的是一个C# 使用授权配置IdentityServerJwt身份验证,c#,asp.net-core,asp.net-mvc-3,asp.net-identity,hangfire,C#,Asp.net Core,Asp.net Mvc 3,Asp.net Identity,Hangfire,我有一个Blazor webassembly应用程序,它使用IdentityServerJwt AddAuthentication,并且正在使用Hangfire。我正试图将Hangfire配置为只允许管理员用户根据文章进行授权,但我得到的是一个没有为方案“承载者”注册身份验证处理程序的错误。我应该添加什么作为身份验证方案。JwtBearerDefaults.AuthenticationScheme`不起作用 我错过了什么 public partial class Startup
没有为方案“承载者”注册身份验证处理程序的错误。我应该添加什么作为身份验证方案
。JwtBearerDefaults.AuthenticationScheme`不起作用
我错过了什么
public partial class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
string handfirepolicyname="HangfirePolicyName";
public void ConfigureServices(IServiceCollection services)
{
...Code removed for brevity
services.AddAuthentication().AddIdentityServerJwt();
services.AddAuthorization(options =>
{
options.AddPolicy(handfirepolicyname, builder =>
{ builder.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme).RequireAuthenticatedUser();
builder.RequireRole("admin");
});
});
var hangfireConnectionstring = "SomeHangfireDatabaseConnectionString";
var mySqlStorageOptions = new MySqlStorageOptions();
var mySqlStorage = new MySqlStorage(hangfireConnectionstring, mySqlStorageOptions);
services.AddHangfire(config => config.UseStorage(mySqlStorage));
services.AddHangfireServer();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ApplicationIdentityDbContext identityDbContext)
{
...Code removed for brevity
app.UseIdentityServer();
app.UseAuthentication();
app.UseAuthorization();
//UseAuthentication, UseAuthorization should be before UseHangfireDashboard
app.UseHangfireDashboard();
app.UseEndpoints(endpoints =>
{
endpoints.MapHangfireDashboard("/hangfire", new DashboardOptions()
{
Authorization = new List<IDashboardAuthorizationFilter> { }
}).RequireAuthorization(handfirepolicyname);
});
}
您是否忘记配置身份验证(添加承载选项)?请参阅
No authentication handler is registered for the scheme 'Bearer'. The registered schemes are: Identity.Application, Identity.External, Identity.TwoFactorRememberMe, Identity.TwoFactorUserId, idsrv, idsrv.external, IdentityServerJwt, IdentityServerJwtBearer. Did you forget to call AddAuthentication().Add[SomeAuthHandler]("Bearer",...)?