Skip to content
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

JWT.Headers() return type is different between .NET Core and .NET Framework #72

Closed
sandersaares opened this issue Aug 18, 2017 · 4 comments

Comments

@sandersaares
Copy link
Contributor

sandersaares commented Aug 18, 2017

Given this JOSE object;

eyJhbGciOiJSUzUxMiIsIng1YyI6WyJNSUlDNHpDQ0FjdWdBd0lCQWdJUUVUd2dNdEVERmJkSSt5c2RGajR6NmpBTkJna3Foa2lHOXcwQkFRMEZBREFNTVFvd0NBWURWUVFERXdGQ01CNFhEVEUyTURVeU56RXlOVEUwTWxvWERUTTVNVEl6TVRJek5UazFPVm93RERFS01BZ0dBMVVFQXhNQlFqQ0NBU0l3RFFZSktvWklodmNOQVFFQkJRQURnZ0VQQURDQ0FRb0NnZ0VCQU1oL3ZQRm1SSEF1NHhzcXNEUTBvOFpjbVg4cHFBN1ZzQVpiMCs5WGlDdldUMlR5SW9OQ0hvZC9DWkhZQ0p6dm1JSTIrZHBGK3p5U3NYZWI5V3lJdE0xU3FVQ0NCOGlHZFFDR0RPNkZpaDhRWjdGZTh1b3FvaGE0TTJ4OG53TXlTK0l3RDRPSG1ReFZ4TjdnSkN2TlN6S2ZPSmkwbUIxNWZ5N3pqKzUrOHphdkl6cVVWcUhMSWxzUWxtc0hSY2J3dHNsTlMvb0F0RXd6VWRmUi9NOGhjc0lnajdVRHBIT21CS0wzaU8xTXp5bW5OeVhqVEhScFA5alBDN0NkVEZjWEMxbzdnWTk5VWhTSmZ0eEd4aHJ5VDEwU1ZjZXZWZC9XRFdZNTF2SlZueG5IVFEyaFpRVkxOM0JucmZHMEIxbmhHZ0dMeCtqTW0rMktBL3VCM0NaVVNRY0NBd0VBQWFOQk1EOHdQUVlEVlIwQkJEWXdOSUFRRmtxUnpoWEhWV0pkOWVXTHgyL2lZcUVPTUF3eENqQUlCZ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baySmN6q5M1jbQaSYNvbbA14_Cgo9bRdVmLRtF01faA5FBvUY3mGX9LsBLbAxoshLAuvf2oW0KSuS3UwkkfRdAM11TVEAsc0XMA
yZxKBSWTtMkWW-h26AO9IdXoosQZmwId6IuQvtFE-Dubzp8ehuT07KVvW7LPrFV87tge5rE90z9PpsGSjLqPGauXJ7kbdvXnwpj6o4AOSpo69wSJ3vKvjggbqpUYB-Xv83w

JWT.Headers() returns the following on .NET Framework 4.7:

Count = 3
    [0]: {[alg, RS512]}
    [1]: {[x5c, System.Object[]]}
    [2]: {[typ, AxinomSignedEnvelope]}

And the following on .NET Core 2.0:

Count = 3
    [0]: {[alg, RS512]}
    [1]: {[x5c, [
  "MIIC4zCCAcugAwIBAgIQETwgMtEDFbdI+ysdFj4z6jANBgkqhkiG9w0BAQ0FADAMMQowCAYDVQQDEwFCMB4XDTE2MDUyNzEyNTE0MloXDTM5MTIzMTIzNTk1OVowDDEKMAgGA1UEAxMBQjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMh/vPFmRHAu4xsqsDQ0o8ZcmX8pqA7VsAZb0+9XiCvWT2TyIoNCHod/CZHYCJzvmII2+dpF+zySsXeb9WyItM1SqUCCB8iGdQCGDO6Fih8QZ7Fe8uoqoha4M2x8nwMyS+IwD4OHmQxVxN7gJCvNSzKfOJi0mB15fy7zj+5+8zavIzqUVqHLIlsQlmsHRcbwtslNS/oAtEwzUdfR/M8hcsIgj7UDpHOmBKL3iO1MzymnNyXjTHRpP9jPC7CdTFcXC1o7gY99UhSJftxGxhryT10SVcevVd/WDWY51vJVnxnHTQ2hZQVLN3BnrfG0B1nhGgGLx+jMm+2KA/uB3CZUSQcCAwEAAaNBMD8wPQYDVR0BBDYwNIAQFkqRzhXHVWJd9eWLx2/iYqEOMAwxCjAIBgNVBAMTAUKCEBE8IDLRAxW3SPsrHRY+M+owDQYJKoZIhvcNAQENBQADggEBADazg6z9y9Cei0CHOm1+2AyLxOD77ChP6WIpd4NvgzmNQMpntCqcVkX9DGi8GPMrljA06dIItN9CwMHta60dpHzkACWjGPs4QGjrl4VNyCGz9iywVWIXC4+bllmuZzRzjlDS8cpFkyWLN6LJa5CItNdgNqzAi43frkZ3/e2jvJXitbjxvesq5EzshofzSLGah+W9wZFxWV9jGwRqxKETl26l4zS4Bm5XnQhog/OK2zQxsXKIUIhtPXv4yBD3RYUghVN8KA6T524sl+40mmEjzrSN+sw1UVCAC/MZYot/hQa5r5R9ixm7Ozdx4HDaItZnKgLZa2YhIfHkdEDScmWwGlY="
]]}
    [2]: {[typ, AxinomSignedEnvelope]}

Those x5c values are object[] and System.Collections.Generic.ICollection<Newtonsoft.Json.Linq.JToken>, respectively.

This difference in data types is making it difficult to write portable code. The Headers() function should return the same thing for the same input data on every platform.

@dvsekhvalnov
Copy link
Owner

dvsekhvalnov commented Aug 18, 2017

Hi @sandersaares ,

well, this is difference between NewtonSoft.Json (default for net core) and JavaScriptSerializer (default for .net framework).

I can't think of any good way to align those (let me know if you have an idea). Simply because there can be anything in a header.

Possible options are:

  1. Force NewtonSoft.Json, via
var test = JWT.Headers(header, new JwtSettings().RegisterMapper(new NewtonsoftMapper()));
  1. Customize Newtonsoft.Json configuration to return array of strings or objects instead of what it is returning. (submit a patch if you figure it out)

  2. Customize JavaScriptSerializer to return array of strings instead (unsure it is possible)

  3. You can go with completely custom IJsonMapper implementation that will align deserialization results on both platforms.

@dvsekhvalnov
Copy link
Owner

@sandersaares
Copy link
Contributor Author

I see what you mean. So .Headers() just returns the raw output of the deserialization because it is just arbitrary JSON. Okay, understood. Forcing Newtonsoft.Json will probably be an OK solution for my case. Thanks for quick explanation!

@dvsekhvalnov
Copy link
Owner

I'll open follow up #73 . Probably will consider in a future. Returning Newtonsoft specific classes seems slightly odd to me right now.

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

2 participants