Skip to content

Could not parse JWS from JSON. #57

Open
Bdaya-Dev/jose
#7
@xprikryl2

Description

@xprikryl2

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions