From e7d22e24dbe8d8ba0d10a30923839ce8db70b19e Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 23 Oct 2020 14:57:35 +1100 Subject: [PATCH] ensures middleware is registered and the external cookie auth is registered. --- .../BackOfficeApplicationBuilderExtensions.cs | 2 +- .../BackOfficeServiceCollectionExtensions.cs | 12 ++++++--- ...ceExternalLoginProviderErrorMiddleware.cs} | 2 +- .../Runtime/BackOfficeComposer.cs | 1 + .../IBackOfficeExternalLoginProviders.cs | 25 +++++++++++++++++++ 5 files changed, 37 insertions(+), 5 deletions(-) rename src/Umbraco.Web.BackOffice/Middleware/{BackOfficeExternalLoginProviderErrorMiddlware.cs => BackOfficeExternalLoginProviderErrorMiddleware.cs} (95%) diff --git a/src/Umbraco.Web.BackOffice/Extensions/BackOfficeApplicationBuilderExtensions.cs b/src/Umbraco.Web.BackOffice/Extensions/BackOfficeApplicationBuilderExtensions.cs index 7002203d33..d32351fdc6 100644 --- a/src/Umbraco.Web.BackOffice/Extensions/BackOfficeApplicationBuilderExtensions.cs +++ b/src/Umbraco.Web.BackOffice/Extensions/BackOfficeApplicationBuilderExtensions.cs @@ -49,7 +49,7 @@ namespace Umbraco.Extensions app.UseUmbracoRuntimeMinification(); app.UseMiddleware(); - app.UseMiddleware(); + app.UseMiddleware(); return app; } diff --git a/src/Umbraco.Web.BackOffice/Extensions/BackOfficeServiceCollectionExtensions.cs b/src/Umbraco.Web.BackOffice/Extensions/BackOfficeServiceCollectionExtensions.cs index 71fa97b9cb..36e48cafb4 100644 --- a/src/Umbraco.Web.BackOffice/Extensions/BackOfficeServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.BackOffice/Extensions/BackOfficeServiceCollectionExtensions.cs @@ -39,7 +39,13 @@ namespace Umbraco.Extensions services.AddSingleton(); services .AddAuthentication(Constants.Security.BackOfficeAuthenticationType) - .AddCookie(Constants.Security.BackOfficeAuthenticationType); + .AddCookie(Constants.Security.BackOfficeAuthenticationType) + .AddCookie(Constants.Security.BackOfficeExternalAuthenticationType, o => + { + o.Cookie.Name = Constants.Security.BackOfficeExternalAuthenticationType; + o.ExpireTimeSpan = TimeSpan.FromMinutes(5); + }); + // TODO: Need to add more cookie options, see https://github.com/dotnet/aspnetcore/blob/3.0/src/Identity/Core/src/IdentityServiceCollectionExtensions.cs#L45 services.ConfigureOptions(); @@ -58,8 +64,6 @@ namespace Umbraco.Extensions { services.AddDataProtection(); - services.TryAddScoped(); - services.BuildUmbracoBackOfficeIdentity() .AddDefaultTokenProviders() .AddUserStore() @@ -95,6 +99,8 @@ namespace Umbraco.Extensions // CUSTOM: services.TryAddScoped(); services.TryAddScoped(); + services.TryAddScoped(); + services.TryAddSingleton(); return new IdentityBuilder(typeof(BackOfficeIdentityUser), services); } diff --git a/src/Umbraco.Web.BackOffice/Middleware/BackOfficeExternalLoginProviderErrorMiddlware.cs b/src/Umbraco.Web.BackOffice/Middleware/BackOfficeExternalLoginProviderErrorMiddleware.cs similarity index 95% rename from src/Umbraco.Web.BackOffice/Middleware/BackOfficeExternalLoginProviderErrorMiddlware.cs rename to src/Umbraco.Web.BackOffice/Middleware/BackOfficeExternalLoginProviderErrorMiddleware.cs index 0a58f0018b..1a2d5b20e7 100644 --- a/src/Umbraco.Web.BackOffice/Middleware/BackOfficeExternalLoginProviderErrorMiddlware.cs +++ b/src/Umbraco.Web.BackOffice/Middleware/BackOfficeExternalLoginProviderErrorMiddleware.cs @@ -16,7 +16,7 @@ namespace Umbraco.Web.BackOffice.Middleware /// When an external login provider registers an error with during the OAuth process, /// this middleware will detect that, store the errors into cookie data and redirect to the back office login so we can read the errors back out. /// - public class BackOfficeExternalLoginProviderErrorMiddlware : IMiddleware + public class BackOfficeExternalLoginProviderErrorMiddleware : IMiddleware { public async Task InvokeAsync(HttpContext context, RequestDelegate next) { diff --git a/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs b/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs index fbd4d02732..795ad856d3 100644 --- a/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs +++ b/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs @@ -31,6 +31,7 @@ namespace Umbraco.Web.BackOffice.Runtime composition.Register(Lifetime.Request); composition.RegisterUnique(); + composition.RegisterUnique(); composition.RegisterUnique(); // register back office trees diff --git a/src/Umbraco.Web.Common/Security/IBackOfficeExternalLoginProviders.cs b/src/Umbraco.Web.Common/Security/IBackOfficeExternalLoginProviders.cs index 106f5378bb..85dbf95272 100644 --- a/src/Umbraco.Web.Common/Security/IBackOfficeExternalLoginProviders.cs +++ b/src/Umbraco.Web.Common/Security/IBackOfficeExternalLoginProviders.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Text; namespace Umbraco.Web.Common.Security @@ -23,6 +24,30 @@ namespace Umbraco.Web.Common.Security bool HasDenyLocalLogin(); } + // TODO: This class is just a placeholder for later + public class NopBackOfficeExternalLoginProviders : IBackOfficeExternalLoginProviders + { + public ExternalSignInAutoLinkOptions Get(string authenticationType) + { + return null; + } + + public string GetAutoLoginProvider() + { + return null; + } + + public IEnumerable GetBackOfficeProviders() + { + return Enumerable.Empty(); + } + + public bool HasDenyLocalLogin() + { + return false; + } + } + // TODO: we'll need to register these somehow public class BackOfficeExternalLoginProvider {