Skip to content

Commit

Permalink
Small refactor of Saml2SecurityTokenHandler
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 24927af commit 3eae565
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,18 +297,22 @@ private ClaimsPrincipal ValidateToken(Saml2SecurityToken samlToken, string token
return new ClaimsPrincipal(identity);
}

private static async Task<TokenValidationParameters> PopulateValidationParametersWithCurrentConfigurationAsync(
TokenValidationParameters validationParameters)
{
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));
private static async Task<TokenValidationParameters> PopulateValidationParametersWithCurrentConfigurationAsync(TokenValidationParameters validationParameters)
{
if (validationParameters.ConfigurationManager == null)
{
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 3eae565

Please sign in to comment.