Skip to content

Commit

Permalink
Update CreateJwtPayload
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhiggins732 committed Feb 24, 2024
1 parent f50da79 commit 57fbf76
Showing 1 changed file with 0 additions and 69 deletions.
69 changes: 0 additions & 69 deletions src/IdentityServer8/src/Extensions/TokenExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,75 +92,6 @@ public static JwtPayload CreateJwtPayload(this Token token, ISystemClock clock,

}

/*
private static JwtPayload ParseJsonClaimsWithNewtonsoft(ILogger logger, JwtPayload payload, List<Claim> jsonClaims)
{
try
{
var jsonTokens = jsonClaims.Select(x => new { x.Type, JsonValue = JRaw.Parse(x.Value) }).ToArray();
var jsonObjects = jsonTokens.Where(x => x.JsonValue.Type == JTokenType.Object).ToArray();
var jsonObjectGroups = jsonObjects.GroupBy(x => x.Type).ToArray();
foreach (var group in jsonObjectGroups)
{
if (payload.ContainsKey(group.Key))
{
throw new Exception($"Can't add two claims where one is a JSON object and the other is not a JSON object ({group.Key})");
}
if (group.Skip(1).Any())
{
// add as array
payload.Add(group.Key, group.Select(x => x.JsonValue).ToArray());
}
else
{
// add just one
payload.Add(group.Key, group.First().JsonValue);
}
}
var jsonArrays = jsonTokens.Where(x => x.JsonValue.Type == JTokenType.Array).ToArray();
var jsonArrayGroups = jsonArrays.GroupBy(x => x.Type).ToArray();
foreach (var group in jsonArrayGroups)
{
if (payload.ContainsKey(group.Key))
{
throw new Exception(
$"Can't add two claims where one is a JSON array and the other is not a JSON array ({group.Key})");
}
var newArr = new List<JToken>();
foreach (var arrays in group)
{
var arr = (JArray) arrays.JsonValue;
newArr.AddRange(arr);
}
// add just one array for the group/key/claim type
payload.Add(group.Key, newArr.ToArray());
}
var unsupportedJsonTokens = jsonTokens.Except(jsonObjects).Except(jsonArrays).ToArray();
var unsupportedJsonClaimTypes = unsupportedJsonTokens.Select(x => x.Type).Distinct().ToArray();
if (unsupportedJsonClaimTypes.Any())
{
throw new Exception(
$"Unsupported JSON type for claim types: {unsupportedJsonClaimTypes.Aggregate((x, y) => x + ", " + y)}");
}
return payload;
}
catch (Exception ex)
{
logger.LogCritical(ex, "Error creating a JSON valued claim");
throw;
}
}
*/


private static JwtPayload ParseJsonClaimsWithSystemTextJson(ILogger logger, JwtPayload payload, List<Claim> jsonClaims)
{
try
Expand Down

0 comments on commit 57fbf76

Please # to comment.