Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TVP to check if Token Identifier can be logged #2002

Merged
merged 1 commit into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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