HangfireIO / Hangfire

An easy way to perform background job processing in .NET and .NET Core applications. No Windows Service or separate process required
https://www.hangfire.io
Other
9.43k stars 1.7k forks source link

Feature Request: Authorization Delegate that can be used instead of the Authorization Filter #2427

Open Banner-Keith opened 4 months ago

Banner-Keith commented 4 months ago

While configuring hangfire dashboard I was thinking it would be nice to provide an authorization delegate that can be used instead of using the authorization filter. Under the hood it could still do the same thing, but the way the user wires it up would be simpler.

app.UseHangfireDashboard(options: new DashboardOptions
{
    // Authorization = [new HangfireDashboardAuthorizationFilter()],
    AuthorizationDelegate = context =>
    {
        HttpContext httpContext = context.GetHttpContext();

        return httpContext.User.IsInRole("Developer");
    }
});

Under the hood the authorization delegate could be provided to a default internal AuthorizationFilter. And the existing Authorization property could take priority if someone provides both. Or as mentioned in the documentation "The second step is to pass it to the UseHangfireDashboard method. You can pass multiple filters, and the access will be granted only if all of them return true." we could make sure that all (not including the default local only filter) return true.

I would be willing to open a PR with the change if you are open to it.