Skip to content

why IsAuthenticated and IsInRole always false in HangfireAuthorizationFilter? #269

@urmatgit

Description

@urmatgit

log in as an administrator

Startup.cs
...
services.AddHangfire(x => x.UseSQLiteStorage(_configuration.GetConnectionString("DefaultConnectionSqlite")));
services.AddHangfireServer();
...
...
app.UseHangfireDashboard("/jobs", new DashboardOptions
{
DashboardTitle = localizer["BlazorHero Jobs"],
Authorization = new[] { new HangfireAuthorizationFilter() }
});
...
public class HangfireAuthorizationFilter : IDashboardAuthorizationFilter
{
public bool Authorize(DashboardContext context)
{
//TODO implement authorization logic

        var httpContext = context.GetHttpContext();

        // Allow all authenticated users to see the Dashboard (potentially dangerous).
        var IsAuthenticated = httpContext.User.Identity.IsAuthenticated;
        var IsInRole= httpContext.User.IsInRole(Permissions.Hangfire.View);
        //return httpContext.User.Identity.IsAuthenticated;
        //return httpContext.User.IsInRole(Permissions.Hangfire.View);

        return true;
    }
}

...
2021-08-10_10h53_24

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions