Skip to content

Commit

Permalink
remove reference to SecurityTokenUnableToValidateException as it is n…
Browse files Browse the repository at this point in the history
…ot used
  • Loading branch information
Brent Schmaltz committed Mar 28, 2023
1 parent 5d49e7c commit 6d4c2ee
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1230,8 +1230,6 @@ private async Task<TokenValidationResult> ValidateTokenAsync(JsonWebToken jsonWe

return tokenValidationResult;
}
// using 'GetType()' instead of 'is' as SecurityTokenUnableToValidException (and others) extend SecurityTokenInvalidSignatureException
// we want to make sure that the clause for SecurityTokenUnableToValidateException is hit so that the ValidationFailure is checked
else if (TokenUtilities.IsRecoverableException(tokenValidationResult.Exception))
{
// If we were still unable to validate, attempt to refresh the configuration and validate using it
Expand Down
16 changes: 4 additions & 12 deletions src/Microsoft.IdentityModel.Tokens/TokenUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,9 @@ internal static IEnumerable<Claim> MergeClaims(IEnumerable<Claim> claims, IEnume
/// <returns><c>true</c> if the exception is certain types of exceptions otherwise, <c>false</c>.</returns>
internal static bool IsRecoverableException(Exception exception)
{
// using 'GetType()' instead of 'is' as SecurityTokenUnableToValidException (and others) extend SecurityTokenInvalidSignatureException
// we want to make sure that the clause for SecurityTokenUnableToValidateException is hit so that the ValidationFailure is checked
return exception.GetType().Equals(typeof(SecurityTokenInvalidSignatureException))
|| exception is SecurityTokenInvalidIssuerException
// we should not try to revalidate with the LKG or request a refresh if the token has an invalid lifetime
|| (exception as SecurityTokenUnableToValidateException)?.ValidationFailure != ValidationFailure.InvalidLifetime
|| exception is SecurityTokenSignatureKeyNotFoundException;
return exception is SecurityTokenInvalidSignatureException
|| exception is SecurityTokenInvalidIssuerException
|| exception is SecurityTokenSignatureKeyNotFoundException;
}

/// <summary>
Expand All @@ -217,11 +213,7 @@ internal static bool IsRecoverableConfiguration(string kid, BaseConfiguration cu
{
return isRecoverableSigningKey.Value;
}
else if ((currentException as SecurityTokenUnableToValidateException)?.ValidationFailure == ValidationFailure.InvalidIssuer)
{
return isRecoverableIssuer.Value && isRecoverableSigningKey.Value;
}
else if (currentException.GetType().Equals(typeof(SecurityTokenInvalidSignatureException)))
else if (currentException is SecurityTokenInvalidSignatureException)
{
SecurityKey currentSigningKey = currentConfiguration.SigningKeys.FirstOrDefault(x => x.KeyId == kid);
if (currentSigningKey == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1271,10 +1271,6 @@ private static bool ValidateSignature(byte[] encodedBytes, byte[] signature, Sec
/// If the <paramref name="token"/> has a key identifier and none of the <see cref="SecurityKey"/>(s) provided result in a validated signature.
/// This can indicate that a key refresh is required.
/// </exception>
/// <exception cref="SecurityTokenUnableToValidateException">
/// If the <paramref name="token"/> has a key identifier and none of the <see cref="SecurityKey"/>(s) provided result in a validated signature as well as the token
/// had validation errors or lifetime or issuer. This is not intended to be a signal to refresh keys.
/// </exception>
/// <exception cref="SecurityTokenInvalidSignatureException">If after trying all the <see cref="SecurityKey"/>(s), none result in a validated signature AND the <paramref name="token"/> does not have a key identifier.</exception>
/// <returns>A <see cref="JwtSecurityToken"/> that has the signature validated if token was signed.</returns>
/// <remarks><para>If the <paramref name="token"/> is signed, the signature is validated even if <see cref="TokenValidationParameters.RequireSignedTokens"/> is false.</para>
Expand Down

0 comments on commit 6d4c2ee

Please sign in to comment.