Skip to content

Commit

Permalink
added a method to concat Audience and Audiences when writing to json
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshLozensky committed May 28, 2024
1 parent 243235c commit 03fd778
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -708,23 +708,19 @@ internal static void WriteJwsPayload(

if (!tokenDescriptor.Audiences.IsNullOrEmpty())
{
writer.WritePropertyName(JwtPayloadUtf8Bytes.Aud);
writer.WriteStartArray();
foreach (string audience in tokenDescriptor.Audiences) { writer.WriteStringValue(audience); }

if (!string.IsNullOrEmpty(tokenDescriptor.Audience))
writer.WriteStringValue(tokenDescriptor.Audience);
if (!tokenDescriptor.Audience.IsNullOrEmpty())
JsonPrimitives.WriteStrings(ref writer, JwtPayloadUtf8Bytes.Aud, tokenDescriptor.Audiences, tokenDescriptor.Audience);
else
JsonPrimitives.WriteStrings(ref writer, JwtPayloadUtf8Bytes.Aud, tokenDescriptor.Audiences);

writer.WriteEndArray();
audienceSet = true;
}
else if (!string.IsNullOrEmpty(tokenDescriptor.Audience))
else if (!tokenDescriptor.Audience.IsNullOrEmpty())
{
writer.WritePropertyName(JwtPayloadUtf8Bytes.Aud);
writer.WriteStringValue(tokenDescriptor.Audience);
audienceSet = true;
}

if (!string.IsNullOrEmpty(tokenDescriptor.Issuer))
{
issuerSet = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,15 @@ public static void WriteStrings(ref Utf8JsonWriter writer, ReadOnlySpan<byte> pr

writer.WriteEndArray();
}
#endregion

public static void WriteStrings(ref Utf8JsonWriter writer, ReadOnlySpan<byte> propertyName, IList<string> strings, string extraString)
{
writer.WriteStartArray(propertyName);
foreach (string str in strings)
writer.WriteStringValue(str);
writer.WriteStringValue(extraString);
writer.WriteEndArray();
}
#endregion
}
}

0 comments on commit 03fd778

Please sign in to comment.