hasValidSignature static method

bool hasValidSignature(
  1. DoxRequest req, {
  2. bool absolute = true,
})

True when req has a valid signature that has not expired.

Implementation

static bool hasValidSignature(DoxRequest req, {bool absolute = true}) {
  String? signature = req.uri.queryParameters['signature'];
  if (signature == null) return false;
  String query = req.uri.query.split('&').where(_notSignature).join('&');
  String path = req.uri.path;
  String url = query.isEmpty ? path : '$path?$query';
  if (absolute) {
    url = '${req.scheme()}://${req.header('host') ?? ''}$url';
  }
  if (!_signedBy(url, signature)) return false;
  String? expires = req.uri.queryParameters['expires'];
  if (expires == null) return true;
  int? at = int.tryParse(expires);
  return at != null && DateTime.now().millisecondsSinceEpoch ~/ 1000 <= at;
}