diff --git a/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Configuration/FacebookLoginConfiguration.cs b/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Configuration/FacebookLoginConfiguration.cs index 7aff0e829c9..51ea48644c9 100644 --- a/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Configuration/FacebookLoginConfiguration.cs +++ b/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Configuration/FacebookLoginConfiguration.cs @@ -43,6 +43,13 @@ public void Configure(AuthenticationOptions options) return; } + if (string.IsNullOrWhiteSpace(_facebookSettings.AppId) || string.IsNullOrWhiteSpace(_facebookSettings.AppSecret)) + { + _logger.LogWarning("The Facebook login provider is enabled but not configured."); + + return; + } + var loginSettings = GetFacebookLoginSettingsAsync().GetAwaiter().GetResult(); if (loginSettings == null) { diff --git a/src/OrchardCore.Modules/OrchardCore.GitHub/Configuration/GithubOptionsConfiguration.cs b/src/OrchardCore.Modules/OrchardCore.GitHub/Configuration/GithubOptionsConfiguration.cs index b8fef85de5c..c2096bfd1d4 100644 --- a/src/OrchardCore.Modules/OrchardCore.GitHub/Configuration/GithubOptionsConfiguration.cs +++ b/src/OrchardCore.Modules/OrchardCore.GitHub/Configuration/GithubOptionsConfiguration.cs @@ -32,6 +32,14 @@ public void Configure(AuthenticationOptions options) return; } + if (string.IsNullOrWhiteSpace(_gitHubAuthenticationSettings.ClientID) || + string.IsNullOrWhiteSpace(_gitHubAuthenticationSettings.ClientSecret)) + { + _logger.LogWarning("The Github login provider is enabled but not configured."); + + return; + } + // Register the OpenID Connect client handler in the authentication handlers collection. options.AddScheme(GitHubDefaults.AuthenticationScheme, builder => { diff --git a/src/OrchardCore.Modules/OrchardCore.Google/Authentication/Configuration/GoogleOptionsConfiguration.cs b/src/OrchardCore.Modules/OrchardCore.Google/Authentication/Configuration/GoogleOptionsConfiguration.cs index e6ff3530d4c..944ddd88228 100644 --- a/src/OrchardCore.Modules/OrchardCore.Google/Authentication/Configuration/GoogleOptionsConfiguration.cs +++ b/src/OrchardCore.Modules/OrchardCore.Google/Authentication/Configuration/GoogleOptionsConfiguration.cs @@ -12,27 +12,35 @@ public class GoogleOptionsConfiguration : IConfigureOptions, IConfigureNamedOptions { - private readonly GoogleAuthenticationSettings _gitHubAuthenticationSettings; + private readonly GoogleAuthenticationSettings _googleAuthenticationSettings; private readonly IDataProtectionProvider _dataProtectionProvider; private readonly ILogger _logger; public GoogleOptionsConfiguration( - IOptions gitHubAuthenticationSettings, + IOptions googleAuthenticationSettings, IDataProtectionProvider dataProtectionProvider, ILogger logger) { - _gitHubAuthenticationSettings = gitHubAuthenticationSettings.Value; + _googleAuthenticationSettings = googleAuthenticationSettings.Value; _dataProtectionProvider = dataProtectionProvider; _logger = logger; } public void Configure(AuthenticationOptions options) { - if (_gitHubAuthenticationSettings == null) + if (_googleAuthenticationSettings == null) { return; } + if (string.IsNullOrWhiteSpace(_googleAuthenticationSettings.ClientID) || + string.IsNullOrWhiteSpace(_googleAuthenticationSettings.ClientSecret)) + { + _logger.LogWarning("The Google login provider is enabled but not configured."); + + return; + } + options.AddScheme(GoogleDefaults.AuthenticationScheme, builder => { builder.DisplayName = "Google"; @@ -47,27 +55,27 @@ public void Configure(string name, GoogleOptions options) return; } - if (_gitHubAuthenticationSettings == null) + if (_googleAuthenticationSettings == null) { return; } - options.ClientId = _gitHubAuthenticationSettings.ClientID; + options.ClientId = _googleAuthenticationSettings.ClientID; try { - options.ClientSecret = _dataProtectionProvider.CreateProtector(GoogleConstants.Features.GoogleAuthentication).Unprotect(_gitHubAuthenticationSettings.ClientSecret); + options.ClientSecret = _dataProtectionProvider.CreateProtector(GoogleConstants.Features.GoogleAuthentication).Unprotect(_googleAuthenticationSettings.ClientSecret); } catch { _logger.LogError("The Consumer Secret could not be decrypted. It may have been encrypted using a different key."); } - if (_gitHubAuthenticationSettings.CallbackPath.HasValue) + if (_googleAuthenticationSettings.CallbackPath.HasValue) { - options.CallbackPath = _gitHubAuthenticationSettings.CallbackPath; + options.CallbackPath = _googleAuthenticationSettings.CallbackPath; } - options.SaveTokens = _gitHubAuthenticationSettings.SaveTokens; + options.SaveTokens = _googleAuthenticationSettings.SaveTokens; } public void Configure(GoogleOptions options) => Debug.Fail("This infrastructure method shouldn't be called."); diff --git a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Configuration/AzureADOptionsConfiguration.cs b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Configuration/AzureADOptionsConfiguration.cs index 7bb6aae5dad..95daa4d3b1b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Configuration/AzureADOptionsConfiguration.cs +++ b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Configuration/AzureADOptionsConfiguration.cs @@ -1,6 +1,7 @@ using System.Diagnostics; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.OpenIdConnect; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.Identity.Web; using OrchardCore.Microsoft.Authentication.Settings; @@ -17,10 +18,12 @@ public class AzureADOptionsConfiguration : public const string AzureAdOpenIdConnectScheme = MicrosoftIdentityDefaults.AzureAd + OpenIdConnectDefaults.AuthenticationScheme; private readonly AzureADSettings _azureADSettings; + private readonly ILogger _logger; - public AzureADOptionsConfiguration(IOptions azureADSettings) + public AzureADOptionsConfiguration(IOptions azureADSettings, ILogger logger) { _azureADSettings = azureADSettings.Value; + _logger = logger; } public void Configure(AuthenticationOptions options) @@ -31,6 +34,13 @@ public void Configure(AuthenticationOptions options) return; } + if (string.IsNullOrWhiteSpace(settings.AppId) || string.IsNullOrWhiteSpace(settings.TenantId)) + { + _logger.LogWarning("The AzureAD login provider is enabled but not configured."); + + return; + } + // Register the OpenID Connect client handler in the authentication handlers collection. options.AddScheme(Constants.AzureAd, builder => { diff --git a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Configuration/MicrosoftAccountOptionsConfiguration.cs b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Configuration/MicrosoftAccountOptionsConfiguration.cs index 656631070c7..4d288619e56 100644 --- a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Configuration/MicrosoftAccountOptionsConfiguration.cs +++ b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Configuration/MicrosoftAccountOptionsConfiguration.cs @@ -33,6 +33,14 @@ public void Configure(AuthenticationOptions options) return; } + if (string.IsNullOrWhiteSpace(_microsoftAccountSettings.AppId) || + string.IsNullOrWhiteSpace(_microsoftAccountSettings.AppSecret)) + { + _logger.LogWarning("The Microsoft login provider is enabled but not configured."); + + return; + } + // Register the OpenID Connect client handler in the authentication handlers collection. options.AddScheme(MicrosoftAccountDefaults.AuthenticationScheme, builder => { diff --git a/src/OrchardCore.Modules/OrchardCore.Twitter/Signin/Configuration/TwitterOptionsConfiguration.cs b/src/OrchardCore.Modules/OrchardCore.Twitter/Signin/Configuration/TwitterOptionsConfiguration.cs index 12521516568..5035132fa3f 100644 --- a/src/OrchardCore.Modules/OrchardCore.Twitter/Signin/Configuration/TwitterOptionsConfiguration.cs +++ b/src/OrchardCore.Modules/OrchardCore.Twitter/Signin/Configuration/TwitterOptionsConfiguration.cs @@ -59,6 +59,14 @@ public void Configure(AuthenticationOptions options) return; } + if (string.IsNullOrWhiteSpace(settings.Item1.ConsumerKey) || + string.IsNullOrWhiteSpace(settings.Item1.ConsumerSecret)) + { + _logger.LogWarning("The Twitter login provider is enabled but not configured."); + + return; + } + options.AddScheme(TwitterDefaults.AuthenticationScheme, builder => { builder.DisplayName = "Twitter";