diff --git a/lib/src/util.dart b/lib/src/util.dart index ae73a7d..9316572 100644 --- a/lib/src/util.dart +++ b/lib/src/util.dart @@ -88,9 +88,10 @@ class JsonObject { case Uri: return Uri.parse(v) as T; case DateTime: - return DateTime.fromMillisecondsSinceEpoch(v * 1000) as T; + return DateTime.fromMillisecondsSinceEpoch(((v as num).round() * 1000)) + as T; case Duration: - return Duration(seconds: v) as T; + return Duration(seconds: (v as num).round()) as T; case String: case num: case bool: diff --git a/test/jwt_test.dart b/test/jwt_test.dart index 2b3ecc6..d9a0f02 100644 --- a/test/jwt_test.dart +++ b/test/jwt_test.dart @@ -1,6 +1,6 @@ -import 'package:test/test.dart'; -import 'package:jose/src/jwt.dart'; import 'package:jose/src/jwk.dart'; +import 'package:jose/src/jwt.dart'; +import 'package:test/test.dart'; void main() { group('JWT Examples from RFC7519', () { @@ -153,4 +153,9 @@ void main() { 'AVO9iT5AV4CzvDJCdhSFlQ'); }); }); + + test('JsonWebTokenClaims can handle doubles in expiration', () { + final claims = JsonWebTokenClaims.fromJson({'exp': 1300819380.0}); + expect(claims.expiry, DateTime.fromMillisecondsSinceEpoch(1300819380000)); + }); }