Skip to content

Object cycle detected when running New-Jwt (JSON Serialize issue)  #34

@UberJoe

Description

@UberJoe

There is some issue with JSON Serialize that happens when i try New-Jwt.
I receive the following error:

Line |
  53 |      $jwt = New-JWT -Payload $payload -Algorithm $alg -Secret $key
     |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | A possible object cycle was detected. This can either be due to a cycle or if the object depth is larger than
     | the maximum allowed depth of 64. Consider using ReferenceHandler.Preserve on JsonSerializerOptions to support
     | cycles. Path:
     | $.Members.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.Value.OverloadDefinitions.

Here's the snippet:

$payload = [Ordered]@{
    "iat" = ([System.DateTimeOffset]::Now).ToUnixTimeSeconds()
    "kid" = $islkid
    "hsig" = hashSha256($method + "|" + $webtoken)
    "data" = $data | ConvertTo-Json
}

$encryption = [jwtTypes+encryption]::SHA256
$algorithm = [jwtTypes+algorithm]::RSA
$alg = [jwtTypes+cryptographyType]::new($algorithm, $encryption)

$jwt = New-JWT -Payload $payload -Algorithm $alg -Secret $key
return $jwt

I checked the payload in case there was something strange, but it looks OK:

[iat, 1673873422] 
[kid, \\default\a] 
[hsig, <hash_value>] 
[data, {}]

How can I resolve this error?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions