Hangfire
Hangfire copied to clipboard
Reference to type 'IAuthorizationFilter' claims it is defined in 'Hangfire.Core', but it could not be found
Seems like IAuthorizationFilter is gone, but BasicAuthAuthorizationFilter still tries to implement it.
Packages used:
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.9" />
<PackageReference Include="Hangfire.Core" Version="1.7.9" />
<PackageReference Include="Hangfire.Dashboard.Authorization" Version="3.0.0" />
Unfortunately, Hangfire.Dashboard.Authorization package doesn't support ASP.NET Core yet. So you shuold use .NET Core implementation from Hangfire.Dashboard.BasicAuthorization nuget package (https://github.com/yuzd/Hangfire.Dashboard.BasicAuthorization). They are the same in the basic auth part.
Ah, that makes sense. Thanks.
EDIT: Feel free to close if this is not relevant.
Please keep this open. Having claims based authorization is important for our business requirements. Any ideas on when we can expect this feature to be implemented?
Same here
You can use IDashboardAuthorizationFilter. You dont need Hangfire.Dashboard.Authorization librarby. Works on .NET 5.
public class HangfireAuthorizationFilter : IDashboardAuthorizationFilter
{
public bool Authorize(DashboardContext context)
{
return context.GetHttpContext().User.IsInRole(@"AD group");
}
}
app.UseHangfireDashboard("/hangfire", new DashboardOptions
{
Authorization = new []{ new HangfireAuthorizationFilter() }
});
@mirecad I actually tried that before, but the user on the HttpContext has always an ´IsAuthenticated = false´. I would presume that this has to with the fact that I use token based Authentification via IS4 instead of cookie based auth But I might be wrong.
@NPadrutt I use only IsInRole. But you should check it one more time. I tried my solution several times in the past without success, so I had to use old .NET Framework solution. Now it suddenly works and I was able to migrate this part of my web to .NET 5. My actual authentication is mix of Azure AD auth + custom role resolution as I described in my article https://www.c-sharpcorner.com/article/authorize-asp-net-core-app-by-azure-ad-groups-using-graph-api/.
I decided to use MapHangfireDashboardWithAuthorizationPolicy instead. It allows me to handle redirect well.
I am trying to configure the dashboard with a simple authorization:
app.UseHangfireDashboard("/hangfire", new DashboardOptions
{
Authorization = new[]
{
new BasicAuthAuthorizationFilter(new BasicAuthAuthorizationFilterOptions
{
RequireSsl = false,
SslRedirect = false,
LoginCaseSensitive = false,
Users = new[]
{
new BasicAuthAuthorizationUser
{
Login = "admin",
PasswordClear = "test",
},
},
}),
},
IsReadOnlyFunc = (DashboardContext context) => true,
});
And I am getting the same error