Skip to content

Commit

Permalink
Add TVP to check if Token Identifier can be logged (#2002)
Browse files Browse the repository at this point in the history
  • Loading branch information
sruke authored Jan 19, 2023
1 parent 2d18df9 commit 716124a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ protected TokenValidationParameters(TokenValidationParameters other)
IssuerSigningKeyValidator = other.IssuerSigningKeyValidator;
IssuerValidator = other.IssuerValidator;
LifetimeValidator = other.LifetimeValidator;
LogTokenId = other.LogTokenId;
LogValidationExceptions = other.LogValidationExceptions;
NameClaimType = other.NameClaimType;
NameClaimTypeRetriever = other.NameClaimTypeRetriever;
Expand Down Expand Up @@ -262,6 +263,7 @@ protected TokenValidationParameters(TokenValidationParameters other)
/// </summary>
public TokenValidationParameters()
{
LogTokenId = true;
LogValidationExceptions = true;
RequireExpirationTime = true;
RequireSignedTokens = true;
Expand Down Expand Up @@ -544,6 +546,13 @@ public virtual ClaimsIdentity CreateClaimsIdentity(SecurityToken securityToken,
/// </remarks>
public LifetimeValidator LifetimeValidator { get; set; }

/// <summary>
/// Gets or sets a <see cref="bool"/> that will decide if the token identifier claim needs to be logged.
/// Default value is <c>true</c>.
/// </summary>
[DefaultValue(true)]
public bool LogTokenId { get; set; }

/// <summary>
/// Gets or sets a <see cref="bool"/> that will decide if validation failure needs to be logged as an error.
/// Default value is <c>true</c> for backward compatibility of the behavior.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Microsoft.IdentityModel.Tokens.Tests
{
public class TokenValidationParametersTests
{
int ExpectedPropertyCount = 57;
int ExpectedPropertyCount = 58;

[Fact]
public void Publics()
Expand Down Expand Up @@ -74,6 +74,7 @@ public void Publics()
IssuerSigningKeys = issuerSigningKeys,
IssuerValidator = ValidationDelegates.IssuerValidatorEcho,
LifetimeValidator = ValidationDelegates.LifetimeValidatorReturnsTrue,
LogTokenId = true,
LogValidationExceptions = true,
PropertyBag = propertyBag,
SignatureValidator = ValidationDelegates.SignatureValidatorReturnsJwtTokenAsIs,
Expand Down Expand Up @@ -112,6 +113,7 @@ public void Publics()
validationParametersSets.IssuerSigningKeys = issuerSigningKeysDup;
validationParametersSets.IssuerValidator = ValidationDelegates.IssuerValidatorEcho;
validationParametersSets.LifetimeValidator = ValidationDelegates.LifetimeValidatorReturnsTrue;
validationParametersSets.LogTokenId = true;
validationParametersSets.LogValidationExceptions = true;
validationParametersSets.PropertyBag = propertyBag;
validationParametersSets.SignatureValidator = ValidationDelegates.SignatureValidatorReturnsJwtTokenAsIs;
Expand All @@ -125,7 +127,7 @@ public void Publics()
validationParametersSets.ValidIssuer = validIssuer;
validationParametersSets.ValidIssuers = validIssuers;
validationParametersSets.ValidTypes = validTypes;

var compareContext = new CompareContext();
IdentityComparer.AreEqual(validationParametersInline, validationParametersSets, compareContext);

Expand Down

0 comments on commit 716124a

Please sign in to comment.