Skip to content

Commit

Permalink
Merge pull request #9 from p-m-j/feature/fix-non-localhost-dashboard
Browse files Browse the repository at this point in the history
Fix dashboard for non localhost instances
  • Loading branch information
nul800sebastiaan authored Mar 7, 2022
2 parents 43eccaa + 7655653 commit 11c6b95
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions Cultiv.Hangfire/HangfireComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
using Microsoft.Extensions.DependencyInjection;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Web.BackOffice.Authorization;
using Umbraco.Cms.Web.Common.ApplicationBuilder;
using Umbraco.Cms.Web.Common.Authorization;

namespace Cultiv.Hangfire
{
Expand Down Expand Up @@ -50,30 +50,20 @@ public void Compose(IUmbracoBuilder builder)

private static void AddAuthorizedUmbracoDashboard(IUmbracoBuilder builder)
{
// Add a named policy to authorize requests to the dashboard
builder.Services.AddAuthorization(options =>
{
options.AddPolicy(Constants.System.HangfireDashboard, policy =>
{
// We require a logged in backoffice user who has access to the settings section
policy.AuthenticationSchemes.Add(Umbraco.Cms.Core.Constants.Security.BackOfficeAuthenticationType);
policy.Requirements.Add(new SectionRequirement(Umbraco.Cms.Core.Constants.Applications.Settings));
});
});

// Add the dashboard and make sure it's authorized with the named policy above
builder.Services.Configure<UmbracoPipelineOptions>(options =>
{
options.AddFilter(new UmbracoPipelineFilter(Constants.System.HangfireDashboard)
{
Endpoints = app => app.UseEndpoints(endpoints =>
{
endpoints.MapHangfireDashboard(
endpoints.MapHangfireDashboardWithAuthorizationPolicy(
pattern: "/umbraco/backoffice/hangfire",
options: new DashboardOptions()).RequireAuthorization(Constants.System.HangfireDashboard);
options: new DashboardOptions(),
authorizationPolicyName: AuthorizationPolicies.SectionAccessSettings);
}).UseHangfireDashboard()
});
});
}
}
}
}

0 comments on commit 11c6b95

Please sign in to comment.