FromPriorJWT.fromCompactSerialization constructor

FromPriorJWT.fromCompactSerialization(
  1. String jwtCompact
)

Implementation

FromPriorJWT.fromCompactSerialization(String jwtCompact) {
  var splitted = jwtCompact.split('.');
  if (splitted.length != 3) {
    throw FormatException(
        'compact serialization must consist of three parts separated by point(.).');
  }
  Map<String, dynamic> header =
      jsonDecode(utf8.decode(base64Decode(addPaddingToBase64(splitted[0]))));
  Map<String, dynamic> payload =
      jsonDecode(utf8.decode(base64Decode(addPaddingToBase64(splitted[1]))));
  signature = splitted[2];

  if (header['typ'] != typ) throw FormatException('typ value must be JWT');
  alg = header['alg'];
  curve = header['crv'];
  kid = header['kid'];

  sub = payload['sub']!;
  iss = payload['iss']!;
  iat =
      DateTime.fromMillisecondsSinceEpoch(payload['iat'] * 1000, isUtc: true);

  //TODO: check signature
}