Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用授权配置IdentityServerJwt身份验证_C#_Asp.net Core_Asp.net Mvc 3_Asp.net Identity_Hangfire - Fatal编程技术网

C# 使用授权配置IdentityServerJwt身份验证

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

我有一个Blazor webassembly应用程序,它使用IdentityServerJwt AddAuthentication,并且正在使用Hangfire。我正试图将Hangfire配置为只允许管理员用户根据文章进行授权,但我得到的是一个
没有为方案“承载者”注册身份验证处理程序的错误。我应该添加什么作为
身份验证方案
。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",...)?