Skip to content

Commit cb46565

Browse files
Brent Schmaltzbrentschmaltz
Brent Schmaltz
authored andcommitted
GetPayloadClaim<object>("aud") will return a single string when aud is a simple string.
1 parent ba30608 commit cb46565

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/Microsoft.IdentityModel.JsonWebTokens/Json/JsonWebToken.PayloadClaimSet.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,14 @@ internal JsonClaimSet CreatePayloadClaimSet(byte[] bytes, int length)
4444
else
4545
{
4646
if (reader.TokenType != JsonTokenType.Null)
47+
{
4748
_audiences.Add(JsonSerializerPrimitives.ReadString(ref reader, JwtRegisteredClaimNames.Aud, ClassName));
48-
49-
claims[JwtRegisteredClaimNames.Aud] = _audiences;
49+
claims[JwtRegisteredClaimNames.Aud] = _audiences[0];
50+
}
51+
else
52+
{
53+
claims[JwtRegisteredClaimNames.Aud] = _audiences;
54+
}
5055
}
5156
}
5257
else if (reader.ValueTextEquals(JwtPayloadUtf8Bytes.Azp))

test/Microsoft.IdentityModel.JsonWebTokens.Tests/JsonWebTokenTests.cs

+9
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,15 @@ public static TheoryData<GetPayloadValueTheoryData> CheckAudienceValuesTheoryDat
275275
{
276276
var theoryData = new TheoryData<GetPayloadValueTheoryData>();
277277

278+
theoryData.Add(new GetPayloadValueTheoryData("stringFromSingleAsObject")
279+
{
280+
ClaimValue = "audience",
281+
PropertyName = "aud",
282+
PropertyType = typeof(object),
283+
PropertyValue = new List<string> { "audience" },
284+
Json = JsonUtilities.CreateUnsignedToken("aud", "audience")
285+
});
286+
278287
theoryData.Add(new GetPayloadValueTheoryData("stringFromSingleInList")
279288
{
280289
ClaimValue = "audience",

0 commit comments

Comments
 (0)