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

Could not parse JWS from JSON. #57

Open
xprikryl2 opened this issue Mar 20, 2024 · 1 comment · Fixed by Bdaya-Dev/jose#7
Open

Could not parse JWS from JSON. #57

xprikryl2 opened this issue Mar 20, 2024 · 1 comment · Fixed by Bdaya-Dev/jose#7

Comments

@xprikryl2
Copy link

Hello,

I have issues with the library after the update to 0.3.3. The problem is caused by this commit (94630ea).

We use the JsonWebSignature.fromJson(Map<String, dynamic> json) method to parse JWS. The issue is caused by the typecasting from the dynamic to List<Map<String, Object>> that throws the Unhandled Exception: type 'List<dynamic>' is not a subtype of type 'List<Map<String, Object>>' in type cast.

If I use map directly as it's implemented in the tests, then everything works. But if you encode the map to JSON and then decode it back to the map, it crashes.

  final testData = {
            'payload':
                'eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGF'
                    'tcGxlLmNvbS9pc19yb290Ijp0cnVlfQ',
            'signatures': [
              {
                'protected': 'eyJhbGciOiJSUzI1NiJ9',
                'header': {'kid': '2010-12-29'},
                'signature': 'cC4hiUPoj9Eetdgtv3hF80EGrhuB__dzERat0XF9g2VtQgr9PJbu3XOiZj5RZ'
                    'mh7AAuHIm4Bh-0Qc_lF5YKt_O8W2Fp5jujGbds9uJdbF9CUAr7t1dnZcAcQjb'
                    'KBYNX4BAynRFdiuB--f_nZLgrnbyTyWzO75vRK5h6xBArLIARNPvkSjtQBMHl'
                    'b1L07Qe7K0GarZRmB_eSN9383LcOLn6_dO--xi12jzDwusC-eOkHWEsqtFZES'
                    'c6BfI7noOPqvhJ1phCnvWh6IeYI2w9QOYEUipUTI8np6LbgGY9Fs98rqVt5AX'
                    'LIhWkWywlVmtVrBp0igcN_IoypGlUPQGe77Rw'
              },
              {
                'protected': 'eyJhbGciOiJFUzI1NiJ9',
                'header': {'kid': 'e9bc097a-ce51-4036-9562-d2ade882db0d'},
                'signature':
                    'DtEhU3ljbEg8L38VWAfUAqOyKAM6-Xx-F4GawxaepmXFCgfTjDxw5djxLa8IS'
                        'lSApmWQxfKTUJqPP3-Kg6NU1Q'
              }
            ]
          };
  final jsonJWS = jsonEncode(testData);
  final jwsMap = jsonDecode(jsonJWS) as Map<String, dynamic>;
  final jws = JsonWebSignature.fromJson(jwsMap);

Thank you for your response.

Best regards,
O.

@ahmednfwela
Copy link

solved in Bdaya-Dev#7

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

Successfully merging a pull request may close this issue.

2 participants