renames umb builder ext class to be more explicit, no more AddAllBackOfficeComponents, just AddBackOffice, removes NuCacheComposer

This commit is contained in:
Shannon
2020-12-22 12:16:37 +11:00
parent 322f0deff3
commit f5e9441e9f
8 changed files with 82 additions and 43 deletions

View File

@@ -1,22 +1,26 @@
using System;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.DependencyInjection;
using Umbraco.Core.DependencyInjection;
using Umbraco.Web.BackOffice.Filters;
using Umbraco.Infrastructure.PublishedCache.Extensions;
using Umbraco.Web.BackOffice.Security;
using Umbraco.Web.Common.Extensions;
namespace Umbraco.Extensions
{
public static class UmbracoBuilderExtensions
/// <summary>
/// Extension methods for <see cref="IUmbracoBuilder"/> for the Umbraco back office
/// </summary>
public static class BackOfficeUmbracoBuilderExtensions
{
public static IUmbracoBuilder AddAllBackOfficeComponents(this IUmbracoBuilder builder)
{
return builder
/// <summary>
/// Adds all required components to run the Umbraco back office
/// </summary>
public static IUmbracoBuilder AddBackOffice(this IUmbracoBuilder builder) => builder
.AddConfiguration()
.AddUmbracoCore()
.AddWebComponents()
.AddRuntimeMinifier()
.AddBackOffice()
.AddBackOfficeAuthentication()
.AddBackOfficeIdentity()
.AddBackOfficeAuthorizationPolicies()
.AddMiniProfiler()
@@ -24,22 +28,29 @@ namespace Umbraco.Extensions
.AddWebServer()
.AddPreviewSupport()
.AddHostedServices()
.AddHttpClients();
}
.AddHttpClients()
.AddNuCache();
public static IUmbracoBuilder AddBackOffice(this IUmbracoBuilder builder)
/// <summary>
/// Adds Umbraco back office authentication requirements
/// </summary>
public static IUmbracoBuilder AddBackOfficeAuthentication(this IUmbracoBuilder builder)
{
builder.Services.AddAntiforgery();
builder.Services
.AddAuthentication() // This just creates a builder, nothing more
// Add our custom schemes which are cookie handlers
// This just creates a builder, nothing more
.AddAuthentication()
// Add our custom schemes which are cookie handlers
.AddCookie(Core.Constants.Security.BackOfficeAuthenticationType)
.AddCookie(Core.Constants.Security.BackOfficeExternalAuthenticationType, o =>
{
o.Cookie.Name = Core.Constants.Security.BackOfficeExternalAuthenticationType;
o.ExpireTimeSpan = TimeSpan.FromMinutes(5);
})
// Although we don't natively support this, we add it anyways so that if end-users implement the required logic
// they don't have to worry about manually adding this scheme or modifying the sign in manager
.AddCookie(Core.Constants.Security.BackOfficeTwoFactorAuthenticationType, o =>
@@ -52,6 +63,9 @@ namespace Umbraco.Extensions
return builder;
}
/// <summary>
/// Adds Identity support for Umbraco back office
/// </summary>
public static IUmbracoBuilder AddBackOfficeIdentity(this IUmbracoBuilder builder)
{
builder.Services.AddUmbracoBackOfficeIdentity();
@@ -59,9 +73,13 @@ namespace Umbraco.Extensions
return builder;
}
/// <summary>
/// Adds Umbraco back office authorization policies
/// </summary>
public static IUmbracoBuilder AddBackOfficeAuthorizationPolicies(this IUmbracoBuilder builder, string backOfficeAuthenticationScheme = Umbraco.Core.Constants.Security.BackOfficeAuthenticationType)
{
builder.Services.AddBackOfficeAuthorizationPolicies(backOfficeAuthenticationScheme);
// TODO: See other TODOs in things like UmbracoApiControllerBase ... AFAIK all of this is only used for the back office
// so IMO these controllers and the features auth policies should just be moved to the back office project and then this
// ext method can be removed.
@@ -70,6 +88,9 @@ namespace Umbraco.Extensions
return builder;
}
/// <summary>
/// Adds Umbraco preview support
/// </summary>
public static IUmbracoBuilder AddPreviewSupport(this IUmbracoBuilder builder)
{
builder.Services.AddSignalR();