Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login providers should not be visible if the service is not configured #15305

Merged
merged 3 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public void Configure(AuthenticationOptions options)
return;
}

if (string.IsNullOrWhiteSpace(_facebookSettings.AppId) || string.IsNullOrWhiteSpace(_facebookSettings.AppSecret))
{
return;
}

var loginSettings = GetFacebookLoginSettingsAsync().GetAwaiter().GetResult();
if (loginSettings == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public void Configure(AuthenticationOptions options)
return;
}

if (string.IsNullOrWhiteSpace(_gitHubAuthenticationSettings.ClientID) ||
string.IsNullOrWhiteSpace(_gitHubAuthenticationSettings.ClientSecret))
{
return;
}

// Register the OpenID Connect client handler in the authentication handlers collection.
options.AddScheme(GitHubDefaults.AuthenticationScheme, builder =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,29 @@ public class GoogleOptionsConfiguration :
IConfigureOptions<AuthenticationOptions>,
IConfigureNamedOptions<GoogleOptions>
{
private readonly GoogleAuthenticationSettings _gitHubAuthenticationSettings;
private readonly GoogleAuthenticationSettings _googleAuthenticationSettings;
private readonly IDataProtectionProvider _dataProtectionProvider;
private readonly ILogger _logger;

public GoogleOptionsConfiguration(
IOptions<GoogleAuthenticationSettings> gitHubAuthenticationSettings,
IOptions<GoogleAuthenticationSettings> googleAuthenticationSettings,
IDataProtectionProvider dataProtectionProvider,
ILogger<GoogleOptionsConfiguration> 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))
{
return;
}
Expand All @@ -47,27 +53,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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public void Configure(AuthenticationOptions options)
return;
}

if (string.IsNullOrWhiteSpace(settings.AppId) || string.IsNullOrWhiteSpace(settings.TenantId))
{
return;
}

// Register the OpenID Connect client handler in the authentication handlers collection.
options.AddScheme(Constants.AzureAd, builder =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ public void Configure(AuthenticationOptions options)
return;
}

if (string.IsNullOrWhiteSpace(settings.Item1.ConsumerKey) ||
string.IsNullOrWhiteSpace(settings.Item1.ConsumerSecret))
{
return;
}

options.AddScheme(TwitterDefaults.AuthenticationScheme, builder =>
{
builder.DisplayName = "Twitter";
Expand Down
Loading