import com.canva.extensions.util.Signer;
import static spark.Spark.post;
// Instantiated here for illustrative purposes. Ideally, provide via the constructor as a singleton.
private static final Signer signer = new Signer("clientSecret");
public static void main(String[] args) {
post("/content/resources/find", (request, response) -> {
var signatures = List.of(request.headers("X-Canva-Signatures").split(","));
var sentAtSeconds = Long.parseLong(request.headers("X-Canva-Timestamp"));
var path = "/content/resources/find";
var signature = signer.signRequest(sentAtSeconds, path, request.body());
if (!signatures.contains(signature)) {
var receivedAtSeconds = System.currentTimeMillis() / 1000;
var leniencyInSeconds = 5 * 60; // 5 minutes
if (receivedAtSeconds - sentAtSeconds > leniencyInSeconds) {
// If the above has passed, then the request is valid and can be handled safely.
// Here we'd handle the findResources request and return a FindResources(Success|Error)Response.