getExpirationDate method

  1. @override
DateTime getExpirationDate()
override

Returns the exact moment when the token expires or the start of the epoch if the expiration date could not be found.

Implementation

@override
DateTime getExpirationDate() {
  if (decodedPayload[_payloadKeyType] == _payloadValueRefresh) {
    //refresh token
    try {
      final int secSinceEpoch = decodedPayload[_payloadKeyExpire] as int;
      return DateTime.fromMillisecondsSinceEpoch(secSinceEpoch * 1000);
    } on TypeError {
      // this method shouldn't throw an exception
      // return epoch start as default
      return DateTime.fromMillisecondsSinceEpoch(0);
    }
  } else {
    //offline token
    try {
      final int secSinceEpoch = decodedPayload[_payloadKeyIssued] as int;
      return DateTime.fromMillisecondsSinceEpoch(secSinceEpoch * 1000)
          .add(_offlineExpiringTime);
    } on TypeError {
      // this method shouldn't throw an exception
      // return epoch start as default
      return DateTime.fromMillisecondsSinceEpoch(0);
    }
  }
}