如何在 F# 中设置 Hangfire 授权?

How to set Hangfire authorization in F#?

根据Hangire Documentation,在C#中可以通过以下方式授权Hangfire仪表板:

// For ASP.NET Core environments, use the GetHttpContext extension method defined in the Hangfire.AspNetCore package.

public class MyAuthorizationFilter : IDashboardAuthorizationFilter
{
    public bool Authorize(DashboardContext context)
    {
        var httpContext = context.GetHttpContext();

        // Allow all authenticated users to see the Dashboard (potentially dangerous).
        return httpContext.User.Identity.IsAuthenticated;
    }
}

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

app.UseHangfireDashboard("/hangfire", new DashboardOptions
{
    Authorization = new [] { new MyAuthorizationFilter() }
});

我正在使用 Giraffe 作为网络服务器,我尝试了以下方式:

type HangfireAuthorization () =
    interface IDashboardAuthorizationFilter with
        override _.Authorize (dc: DashboardContext) =
            false

type WebApp(context: StatelessServiceContext) =
    inherit StatelessService(context)
    //....

    let configureApp (app: IApplicationBuilder) =
            let storageContext = app.ApplicationServices.GetService(typeof<StorageContext>) :?> StorageContext

            let hangfireDashboardOptions: DashboardOptions =
                let x = DashboardOptions()
                x.Authorization <- HangfireAuthorization() // how to correctly set this option?
                x

            app.UseGiraffeErrorHandler(errorHandler)
               .UseCors("AllowCors")
               .UseHangfireDashboard("/hangfire", hangfireDashboardOptions)

如何正确设置Hangfire DashboardOptions的授权字段?

我是这样工作的:

type HangfireAuthorization () =
    interface IDashboardAuthorizationFilter with
        override _.Authorize (dc: DashboardContext) =
            false 

 let hangfireDashboardOptions: DashboardOptions =
     let x = DashboardOptions()
     x.Authorization <- [ HangfireAuthorization() ] // or [| HangfireAuthorization() |]
     x

 app.UseGiraffeErrorHandler(errorHandler)
 .UseCors("AllowCors")
 .UseHangfireDashboard("/hangfire", hangfireDashboardOptions)