hasValidSignature static method
True when req has a valid signature that has not expired.
Implementation
static bool hasValidSignature(DoxRequest req, {bool absolute = true}) {
Map<String, String> params;
try {
params = req.uri.queryParameters;
} on FormatException {
// an escape that is not UTF-8, like `%ff`: Dox never signs one
return false;
}
String? signature = params['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 = params['expires'];
if (expires == null) return true;
int? at = int.tryParse(expires);
return at != null && DateTime.now().millisecondsSinceEpoch ~/ 1000 <= at;
}