diff --git a/src/Umbraco.Web.BackOffice/Security/BackOfficeAuthenticationBuilder.cs b/src/Umbraco.Web.BackOffice/Security/BackOfficeAuthenticationBuilder.cs index 5ccd1c0aa1..bc35e9ad44 100644 --- a/src/Umbraco.Web.BackOffice/Security/BackOfficeAuthenticationBuilder.cs +++ b/src/Umbraco.Web.BackOffice/Security/BackOfficeAuthenticationBuilder.cs @@ -12,18 +12,16 @@ namespace Umbraco.Cms.Web.BackOffice.Security /// public class BackOfficeAuthenticationBuilder : AuthenticationBuilder { - private readonly BackOfficeExternalLoginProviderOptions _loginProviderOptions; + private readonly Action _loginProviderOptions; - public BackOfficeAuthenticationBuilder(IServiceCollection services, BackOfficeExternalLoginProviderOptions loginProviderOptions) + public BackOfficeAuthenticationBuilder( + IServiceCollection services, + Action loginProviderOptions = null) : base(services) - { - _loginProviderOptions = loginProviderOptions; - } + => _loginProviderOptions = loginProviderOptions ?? (x => { }); public string SchemeForBackOffice(string scheme) - { - return Constants.Security.BackOfficeExternalAuthenticationTypePrefix + scheme; - } + => Constants.Security.BackOfficeExternalAuthenticationTypePrefix + scheme; /// /// Overridden to track the final authenticationScheme being registered for the external login @@ -43,7 +41,11 @@ namespace Umbraco.Cms.Web.BackOffice.Security } // add our login provider to the container along with a custom options configuration - Services.AddSingleton(x => new BackOfficeExternalLoginProvider(displayName, authenticationScheme, _loginProviderOptions)); + Services.Configure(authenticationScheme, _loginProviderOptions); + Services.AddSingleton(x => new BackOfficeExternalLoginProvider( + displayName, + authenticationScheme, + x.GetRequiredService>())); Services.TryAddEnumerable(ServiceDescriptor.Singleton, EnsureBackOfficeScheme>()); return base.AddRemoteScheme(authenticationScheme, displayName, configureOptions); diff --git a/src/Umbraco.Web.BackOffice/Security/BackOfficeExternalLoginProvider.cs b/src/Umbraco.Web.BackOffice/Security/BackOfficeExternalLoginProvider.cs index ff2a64f155..42798022b7 100644 --- a/src/Umbraco.Web.BackOffice/Security/BackOfficeExternalLoginProvider.cs +++ b/src/Umbraco.Web.BackOffice/Security/BackOfficeExternalLoginProvider.cs @@ -1,4 +1,5 @@ -using System; +using System; +using Microsoft.Extensions.Options; namespace Umbraco.Cms.Web.BackOffice.Security { @@ -7,11 +8,16 @@ namespace Umbraco.Cms.Web.BackOffice.Security /// public class BackOfficeExternalLoginProvider : IEquatable { - public BackOfficeExternalLoginProvider(string name, string authenticationType, BackOfficeExternalLoginProviderOptions properties) + public BackOfficeExternalLoginProvider(string name, string authenticationType, IOptions properties) { + if (properties is null) + { + throw new ArgumentNullException(nameof(properties)); + } + Name = name ?? throw new ArgumentNullException(nameof(name)); AuthenticationType = authenticationType ?? throw new ArgumentNullException(nameof(authenticationType)); - Options = properties ?? throw new ArgumentNullException(nameof(properties)); + Options = properties.Value; } public string Name { get; } diff --git a/src/Umbraco.Web.BackOffice/Security/BackOfficeExternalLoginProviderOptions.cs b/src/Umbraco.Web.BackOffice/Security/BackOfficeExternalLoginProviderOptions.cs index fa1c1fe487..cdbcd0b8e8 100644 --- a/src/Umbraco.Web.BackOffice/Security/BackOfficeExternalLoginProviderOptions.cs +++ b/src/Umbraco.Web.BackOffice/Security/BackOfficeExternalLoginProviderOptions.cs @@ -1,14 +1,13 @@ -namespace Umbraco.Cms.Web.BackOffice.Security +namespace Umbraco.Cms.Web.BackOffice.Security { - - /// /// Options used to configure back office external login providers /// public class BackOfficeExternalLoginProviderOptions { public BackOfficeExternalLoginProviderOptions( - string buttonStyle, string icon, + string buttonStyle, + string icon, ExternalSignInAutoLinkOptions autoLinkOptions = null, bool denyLocalLogin = false, bool autoRedirectLoginToExternalProvider = false, @@ -22,18 +21,23 @@ CustomBackOfficeView = customBackOfficeView; } - public string ButtonStyle { get; } - public string Icon { get; } + public BackOfficeExternalLoginProviderOptions() + { + } + + public string ButtonStyle { get; set; } = "btn-openid"; + + public string Icon { get; set; } = "fa-user"; /// /// Options used to control how users can be auto-linked/created/updated based on the external login provider /// - public ExternalSignInAutoLinkOptions AutoLinkOptions { get; } + public ExternalSignInAutoLinkOptions AutoLinkOptions { get; set; } /// /// When set to true will disable all local user login functionality /// - public bool DenyLocalLogin { get; } + public bool DenyLocalLogin { get; set; } /// /// When specified this will automatically redirect to the OAuth login provider instead of prompting the user to click on the OAuth button first. @@ -42,7 +46,7 @@ /// This is generally used in conjunction with . If more than one OAuth provider specifies this, the last registered /// provider's redirect settings will win. /// - public bool AutoRedirectLoginToExternalProvider { get; } + public bool AutoRedirectLoginToExternalProvider { get; set; } /// /// A virtual path to a custom angular view that is used to replace the entire UI that renders the external login button that the user interacts with @@ -51,6 +55,6 @@ /// If this view is specified it is 100% up to the user to render the html responsible for rendering the link/un-link buttons along with showing any errors /// that occur. This overrides what Umbraco normally does by default. /// - public string CustomBackOfficeView { get; } + public string CustomBackOfficeView { get; set; } } } diff --git a/src/Umbraco.Web.BackOffice/Security/BackOfficeExternalLoginsBuilder.cs b/src/Umbraco.Web.BackOffice/Security/BackOfficeExternalLoginsBuilder.cs index daea904a49..cab3ea10d1 100644 --- a/src/Umbraco.Web.BackOffice/Security/BackOfficeExternalLoginsBuilder.cs +++ b/src/Umbraco.Web.BackOffice/Security/BackOfficeExternalLoginsBuilder.cs @@ -1,4 +1,4 @@ -using System; +using System; using Microsoft.Extensions.DependencyInjection; namespace Umbraco.Cms.Web.BackOffice.Security @@ -21,9 +21,9 @@ namespace Umbraco.Cms.Web.BackOffice.Security /// /// /// - public BackOfficeExternalLoginsBuilder AddBackOfficeLogin( - BackOfficeExternalLoginProviderOptions loginProviderOptions, - Action build) + public BackOfficeExternalLoginsBuilder AddBackOfficeLogin( + Action build, + Action loginProviderOptions = null) { build(new BackOfficeAuthenticationBuilder(_services, loginProviderOptions)); return this;