Skip to content

Commit

Permalink
fixed bug and made variable names more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshLozensky committed Jun 12, 2024
1 parent 6e73309 commit f01c50d
Showing 1 changed file with 25 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -697,15 +697,15 @@ internal static void WriteJwsPayload(
bool setDefaultTimesOnTokenCreation,
int tokenLifetimeInMinutes)
{
bool audienceChecked = false;
bool descriptorClaimsAudienceChecked = false;
bool audienceSet = false;
bool issuerChecked = false;
bool descriptorClaimsIssuerChecked = false;
bool issuerSet = false;
bool expChecked = false;
bool descriptorClaimsExpChecked = false;
bool expSet = false;
bool iatChecked = false;
bool descriptorClaimsIatChecked = false;
bool iatSet = false;
bool nbfChecked = false;
bool descriptorClaimsNbfChecked = false;
bool nbfSet = false;

writer.WriteStartObject();
Expand Down Expand Up @@ -761,28 +761,31 @@ internal static void WriteJwsPayload(
{
foreach (KeyValuePair<string, object> kvp in tokenDescriptor.Claims)
{
if (!audienceChecked && kvp.Key.Equals(JwtRegisteredClaimNames.Aud, StringComparison.Ordinal))
if (!descriptorClaimsAudienceChecked && kvp.Key.Equals(JwtRegisteredClaimNames.Aud, StringComparison.Ordinal))
{
audienceChecked = true;
if (audienceSet && LogHelper.IsEnabled(EventLogLevel.Informational))
descriptorClaimsAudienceChecked = true;
if (audienceSet)
{
string descriptorMemberName = null;
if (!tokenDescriptor.Audiences.IsNullOrEmpty())
descriptorMemberName = nameof(tokenDescriptor.Audiences);
else if (!string.IsNullOrEmpty(tokenDescriptor.Audience))
descriptorMemberName = nameof(tokenDescriptor.Audience);
if (LogHelper.IsEnabled(EventLogLevel.Informational))
{
string descriptorMemberName = null;
if (!tokenDescriptor.Audiences.IsNullOrEmpty())
descriptorMemberName = nameof(tokenDescriptor.Audiences);
else if (!string.IsNullOrEmpty(tokenDescriptor.Audience))
descriptorMemberName = nameof(tokenDescriptor.Audience);

LogHelper.LogInformation(LogHelper.FormatInvariant(LogMessages.IDX14113, LogHelper.MarkAsNonPII(descriptorMemberName)));
LogHelper.LogInformation(LogHelper.FormatInvariant(LogMessages.IDX14113, LogHelper.MarkAsNonPII(descriptorMemberName)));
}

continue;
}

audienceSet = true;
}

if (!issuerChecked && kvp.Key.Equals(JwtRegisteredClaimNames.Iss, StringComparison.Ordinal))
if (!descriptorClaimsIssuerChecked && kvp.Key.Equals(JwtRegisteredClaimNames.Iss, StringComparison.Ordinal))
{
issuerChecked = true;
descriptorClaimsIssuerChecked = true;
if (issuerSet)
{
if (LogHelper.IsEnabled(EventLogLevel.Informational))
Expand All @@ -794,9 +797,9 @@ internal static void WriteJwsPayload(
issuerSet = true;
}

if (!expChecked && kvp.Key.Equals(JwtRegisteredClaimNames.Exp, StringComparison.Ordinal))
if (!descriptorClaimsExpChecked && kvp.Key.Equals(JwtRegisteredClaimNames.Exp, StringComparison.Ordinal))
{
expChecked = true;
descriptorClaimsExpChecked = true;
if (expSet)
{
if (LogHelper.IsEnabled(EventLogLevel.Informational))
Expand All @@ -808,9 +811,9 @@ internal static void WriteJwsPayload(
expSet = true;
}

if (!iatChecked && kvp.Key.Equals(JwtRegisteredClaimNames.Iat, StringComparison.Ordinal))
if (!descriptorClaimsIatChecked && kvp.Key.Equals(JwtRegisteredClaimNames.Iat, StringComparison.Ordinal))
{
iatChecked = true;
descriptorClaimsIatChecked = true;
if (iatSet)
{
if (LogHelper.IsEnabled(EventLogLevel.Informational))
Expand All @@ -822,9 +825,9 @@ internal static void WriteJwsPayload(
iatSet = true;
}

if (!nbfChecked && kvp.Key.Equals(JwtRegisteredClaimNames.Nbf, StringComparison.Ordinal))
if (!descriptorClaimsNbfChecked && kvp.Key.Equals(JwtRegisteredClaimNames.Nbf, StringComparison.Ordinal))
{
nbfChecked = true;
descriptorClaimsNbfChecked = true;
if (nbfSet)
{
if (LogHelper.IsEnabled(EventLogLevel.Informational))
Expand Down

0 comments on commit f01c50d

Please sign in to comment.