Skip to content

[Bug] JsonWebToken.TryGetPayloadValue() can no longer be used with string arrays #2249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jmprieur opened this issue Aug 22, 2023 · 2 comments
Assignees

Comments

@jmprieur
Copy link
Contributor

jmprieur commented Aug 22, 2023

Consider the following JWT payload:

{
    "prop1": [
      "value1",
      "value2"
    ]
  "exp": 1692706803,
  "iat": 1692703203,
  "nbf": 1692703203
}

The following snippet works just fine on 7.0.0-preview but fails on 7.0.0-preview3 (TryGetPayloadValue returns false). It does work fine if you use an IList<string> instead of the string[]:

           JsonWebToken token = new JsonWebToken("{\"alg\": \"RS256\",\"typ\": \"JWT\"}", 
               "{ \"prop1\": [\"value1\",\"value2\"],  \"exp\": 1692706803,\"iat\": 1692703203,\"nbf\": 1692703203 }");

           // This does not work
           if (token.TryGetPayloadValue("prop1", out string[] array))
           {
               Console.WriteLine("The array has been correctly deserialized.");
           }

           // This does not work
           if (token.TryGetPayloadValue("prop1", out List<string> list))
           {
               Console.WriteLine("The list has been correctly deserialized.");
           }

           // This works
           if (token.TryGetPayloadValue("prop1", out IList<string> ilist))
           {
               Console.WriteLine("The list has been correctly deserialized.");
           }
       }

/cc @brentschmaltz @jennyf19 @keegan-caruso

@jennyf19
Copy link
Collaborator

#2246

@brentschmaltz
Copy link
Member

Dup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants