valid method

String valid({
  1. DateTime? expiresIn,
})

Implementation

String valid({DateTime? expiresIn}) {
  if (expiresIn != null && DateTime.now().isAfter(expiresIn)) {
    throw FormatException('expiresIn should be a future date');
  }

  // default expiration with 1 hour
  final expiration = expiresIn != null
      ? dateToSeconds(expiresIn)
      : dateToSeconds(DateTime.now()) + 3600;

  final header = _generateHeader();
  final payload = _generatePayload({
    'iat': dateToSeconds(DateTime.now()),
    'exp': expiration,
  });
  final signature = _generateSignature(header, payload);

  return '$header.$payload.$signature';
}