Skip to content

Commit

Permalink
Fix erroneous double list allocation in JsonWebToken.Audiences (#2172)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub authored and brentschmaltz committed Sep 7, 2023
1 parent 5ee9f1d commit ff0f190
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/Microsoft.IdentityModel.JsonWebTokens/JsonWebToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -604,19 +604,17 @@ public IEnumerable<string> Audiences
lock (_audiencesLock)
{
if (_audiences == null)

_audiences = new List<string>();

if (Payload.TryGetValue(JwtRegisteredClaimNames.Aud, out JsonElement audiences))
{
if (audiences.ValueKind == JsonValueKind.String)
_audiences = new List<string> { audiences.GetString() };

if (audiences.ValueKind == JsonValueKind.Array)
{
foreach (JsonElement jsonElement in audiences.EnumerateArray())
_audiences.Add(jsonElement.ToString());
}
if (audiences.ValueKind == JsonValueKind.String)
{
_audiences = new List<string> { audiences.GetString() };
}
else if (audiences.ValueKind == JsonValueKind.Array)
{
foreach (JsonElement jsonElement in audiences.EnumerateArray())
_audiences.Add(jsonElement.ToString());
}
}
}
}
Expand Down

0 comments on commit ff0f190

Please sign in to comment.