Skip to content

Commit

Permalink
Made securityToken optional, removed null check and updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iNinja committed Jun 20, 2024
1 parent fe5cbaf commit 64035fe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.IdentityModel.Abstractions;
using Microsoft.IdentityModel.Logging;

#nullable enable
namespace Microsoft.IdentityModel.Tokens
{
/// <summary>
Expand All @@ -23,7 +24,7 @@ namespace Microsoft.IdentityModel.Tokens
/// <remarks>This delegate is not expected to throw.</remarks>
internal delegate AudienceValidationResult ValidateAudience(
IEnumerable<string> audiences,
SecurityToken securityToken,
SecurityToken? securityToken,
TokenValidationParameters validationParameters,
CallContext callContext);

Expand Down Expand Up @@ -107,7 +108,6 @@ public static void ValidateAudience(IEnumerable<string> audiences, SecurityToken
}


#nullable enable
/// <summary>
/// Determines if the audiences found in a <see cref="SecurityToken"/> are valid.
/// </summary>
Expand All @@ -121,7 +121,7 @@ public static void ValidateAudience(IEnumerable<string> audiences, SecurityToken
/// <exception cref="SecurityTokenInvalidAudienceException">If none of the 'audiences' matched either <see cref="TokenValidationParameters.ValidAudience"/> or one of <see cref="TokenValidationParameters.ValidAudiences"/>.</exception>
/// <remarks>An EXACT match is required.</remarks>
#pragma warning disable CA1801 // TODO: remove pragma disable once callContext is used for logging
internal static AudienceValidationResult ValidateAudience(IEnumerable<string> audiences, SecurityToken securityToken, TokenValidationParameters validationParameters, CallContext callContext)
internal static AudienceValidationResult ValidateAudience(IEnumerable<string> audiences, SecurityToken? securityToken, TokenValidationParameters validationParameters, CallContext callContext)
#pragma warning restore CA1801
{
if (validationParameters == null)
Expand All @@ -141,18 +141,6 @@ internal static AudienceValidationResult ValidateAudience(IEnumerable<string> au
return new AudienceValidationResult(Utility.SerializeAsSingleCommaDelimitedString(audiences));
}

if (securityToken == null)
return new AudienceValidationResult(
Utility.SerializeAsSingleCommaDelimitedString(audiences),
ValidationFailureType.NullArgument,
new ExceptionDetail(
new MessageDetail(
LogMessages.IDX10000,
LogHelper.MarkAsNonPII(nameof(securityToken))),
typeof(ArgumentNullException),
new StackFrame(true),
null));

if (audiences == null)
return new AudienceValidationResult(
Utility.SerializeAsSingleCommaDelimitedString(audiences),
Expand Down Expand Up @@ -285,3 +273,4 @@ private static bool AudiencesMatchIgnoringTrailingSlash(string tokenAudience, st

}
}
#nullable disable
Loading

0 comments on commit 64035fe

Please sign in to comment.