Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds support for array-based audience claims in JSON Web Tokens (JWTs) and ensures that tokens contain at least one audience claim when trusted audiences are configured. It also includes comprehensive unit tests for these changes. The review feedback highlights two main improvements: first, avoiding potential null elements in AudienceAsList by using a null-coalescing operator to default to an empty string, and second, removing a redundant .ToList() call in the verification logic to prevent unnecessary memory allocations.
db285bc to
2703416
Compare
| { | ||
| get | ||
| { | ||
| var asList = Audience as List<string>; |
There was a problem hiding this comment.
Could we cast to IEnumerable<string> instead here and then return asEnumerable without allocating a new list?
There was a problem hiding this comment.
Just in case we could also do the following to avoid passing forward something that has deferred execution (like a linq query). But if this is only coming from json maybe it's not a concern:
if (Audience is IReadOnlyCollection<string> asCollection)
{
return asCollection;
}There was a problem hiding this comment.
Since Audience on this Payload class is an object, the default deserialization in SignedToken.cs:
var payloadValue = NewtonsoftJsonSerializer.Instance.Deserialize<TJwsPayload>(TokenEncodingHelpers.Base64UrlToString(encodedPayload));
Converts an array on the aud field into a JArray. The problem here is a Newtonsoft.Json JArray object cannot be cast to a strongly typed List/IEnumerable. I think if we wanted to keep the changes in this AudienceAsList to a minimal on both lines and allocations, it would be adding a custom deserializer to convert a json array of scalar values into a strongly typed list.
2703416 to
fb5c83d
Compare
b/593062491