Hangfire icon indicating copy to clipboard operation
Hangfire copied to clipboard

Reference to type 'IAuthorizationFilter' claims it is defined in 'Hangfire.Core', but it could not be found

Open MaikuMori opened this issue 5 years ago • 8 comments
trafficstars

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" />

MaikuMori avatar Mar 13 '20 00:03 MaikuMori

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.

hyperion-cs avatar Mar 14 '20 16:03 hyperion-cs

Ah, that makes sense. Thanks.

EDIT: Feel free to close if this is not relevant.

MaikuMori avatar Mar 14 '20 16:03 MaikuMori

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?

Reckonian avatar Mar 18 '21 19:03 Reckonian

Same here

mtbayley avatar Apr 01 '21 20:04 mtbayley

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 avatar Jul 15 '21 18:07 mirecad

@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 avatar Jul 16 '21 05:07 NPadrutt

@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/.

mirecad avatar Jul 16 '21 12:07 mirecad

I decided to use MapHangfireDashboardWithAuthorizationPolicy instead. It allows me to handle redirect well.

ltvan avatar Apr 03 '22 12:04 ltvan

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

twojnarowski avatar Aug 04 '23 09:08 twojnarowski