getData static method

BearerTokenResultDTO getData(
  1. String token,
  2. String secretKey
)

Implementation

static BearerTokenResultDTO getData(String token, String secretKey) {
  final List<String> segments = token.split('.');
  if(!(secretKey.length == 16 || secretKey.length == 24 || secretKey.length == 32)) return const BearerTokenResultDTO(status: BearerTokenStatus.brokenSecretKey);
  if(segments.length != 3) return const BearerTokenResultDTO(status: BearerTokenStatus.brokenToken);

  try {
    final Map<String, dynamic> payload = jsonDecode(_decrypt(segments[1], secretKey));

    final DateTime live = DateTime.parse(payload["live"]);
    if (live.compareTo(DateTime.now()) == -1) {
      return const BearerTokenResultDTO(status: BearerTokenStatus.liveIsOver);
    }

    return BearerTokenResultDTO(result: payload["data"], status: BearerTokenStatus.done);
  } catch (e) {
    return const BearerTokenResultDTO(status: BearerTokenStatus.brokenToken);
  }
}