Skip to content

Commit

Permalink
Small refactor of SamlSecurityTokenHandler
Browse files Browse the repository at this point in the history
Refactor PopulateValidationParametersWithCurrentConfigurationAsync null check to guard with an early return.
Rename cloned variable to make code easier to read.
  • Loading branch information
hakon.lerring authored and brentschmaltz committed Mar 13, 2024
1 parent 10c7984 commit 24927af
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1251,17 +1251,19 @@ private ClaimsPrincipal ValidateToken(SamlSecurityToken samlToken, string token,
private static async Task<TokenValidationParameters> PopulateValidationParametersWithCurrentConfigurationAsync(
TokenValidationParameters validationParameters)
{
if (validationParameters.ConfigurationManager != null)
if (validationParameters.ConfigurationManager == null)
{
var currentConfiguration = await validationParameters.ConfigurationManager.GetBaseConfigurationAsync(CancellationToken.None).ConfigureAwait(false);
validationParameters = validationParameters.Clone();
var issuers = new[] { currentConfiguration.Issuer };

validationParameters.ValidIssuers = (validationParameters.ValidIssuers == null ? issuers : validationParameters.ValidIssuers.Concat(issuers));
validationParameters.IssuerSigningKeys = (validationParameters.IssuerSigningKeys == null ? currentConfiguration.SigningKeys : validationParameters.IssuerSigningKeys.Concat(currentConfiguration.SigningKeys));
return validationParameters;
}

return validationParameters;
var currentConfiguration = await validationParameters.ConfigurationManager.GetBaseConfigurationAsync(CancellationToken.None).ConfigureAwait(false);
var validationParametersCloned = validationParameters.Clone();
var issuers = new[] { currentConfiguration.Issuer };

validationParametersCloned.ValidIssuers = (validationParametersCloned.ValidIssuers == null ? issuers : validationParametersCloned.ValidIssuers.Concat(issuers));
validationParametersCloned.IssuerSigningKeys = (validationParametersCloned.IssuerSigningKeys == null ? currentConfiguration.SigningKeys : validationParametersCloned.IssuerSigningKeys.Concat(currentConfiguration.SigningKeys));
return validationParametersCloned;

}

/// <summary>
Expand Down

0 comments on commit 24927af

Please sign in to comment.