{
  "name": "Palanor event: check the signature, then use it",
  "flow": [
    {
      "id": 1,
      "module": "gateway:CustomWebHook",
      "version": 1,
      "parameters": {
        "hook": null,
        "maxResults": 1
      },
      "mapper": {},
      "metadata": {
        "designer": {
          "x": 0,
          "y": 0
        },
        "restore": {
          "parameters": {
            "hook": {
              "label": "Create a webhook on import: turn on Get request headers and JSON pass-through"
            }
          }
        }
      }
    },
    {
      "id": 6,
      "module": "util:SetVariables",
      "version": 1,
      "parameters": {},
      "mapper": {
        "scope": "roundtrip",
        "variables": [
          {
            "name": "signed_content",
            "value": "{{get(map(1.`__IMTHEADERS__`; \"value\"; \"name\"; \"webhook-id\"); 1)}}.{{get(map(1.`__IMTHEADERS__`; \"value\"; \"name\"; \"webhook-timestamp\"); 1)}}.{{1.value}}"
          },
          {
            "name": "received",
            "value": "{{get(map(1.`__IMTHEADERS__`; \"value\"; \"name\"; \"webhook-signature\"); 1)}}"
          },
          {
            "name": "age_seconds",
            "value": "{{formatDate(now; \"X\") - get(map(1.`__IMTHEADERS__`; \"value\"; \"name\"; \"webhook-timestamp\"); 1)}}"
          }
        ]
      },
      "metadata": {
        "designer": {
          "x": 250,
          "y": 0
        }
      }
    },
    {
      "id": 7,
      "module": "util:SetVariables",
      "version": 1,
      "parameters": {},
      "mapper": {
        "scope": "roundtrip",
        "variables": [
          {
            "name": "expected",
            "value": "v1,{{sha256(6.signed_content; \"base64\"; \"PASTE_SECRET_WITHOUT_whsec_\"; \"base64\")}}"
          }
        ]
      },
      "metadata": {
        "designer": {
          "x": 420,
          "y": 0
        }
      }
    },
    {
      "id": 2,
      "module": "builtin:BasicRouter",
      "version": 1,
      "mapper": null,
      "metadata": {
        "designer": {
          "x": 640,
          "y": 0
        }
      },
      "routes": [
        {
          "flow": [
            {
              "id": 3,
              "module": "json:ParseJSON",
              "version": 1,
              "parameters": {
                "type": ""
              },
              "filter": {
                "name": "Signature verifies and is fresh",
                "conditions": [
                  [
                    {
                      "a": "{{6.received}}",
                      "b": "{{7.expected}}",
                      "o": "text:contain"
                    },
                    {
                      "a": "{{6.age_seconds}}",
                      "b": "300",
                      "o": "number:lessorequal"
                    }
                  ]
                ]
              },
              "mapper": {
                "json": "{{1.value}}"
              },
              "metadata": {
                "designer": {
                  "x": 600,
                  "y": -150
                }
              }
            },
            {
              "id": 4,
              "module": "gateway:WebhookRespond",
              "version": 1,
              "parameters": {},
              "mapper": {
                "status": "200",
                "body": "ok",
                "headers": []
              },
              "metadata": {
                "designer": {
                  "x": 900,
                  "y": -150
                }
              }
            }
          ]
        },
        {
          "flow": [
            {
              "id": 5,
              "module": "gateway:WebhookRespond",
              "version": 1,
              "parameters": {},
              "filter": {
                "name": "Signature does not verify, or is old",
                "conditions": [
                  [
                    {
                      "a": "{{6.received}}",
                      "b": "{{7.expected}}",
                      "o": "text:notcontain"
                    }
                  ],
                  [
                    {
                      "a": "{{6.age_seconds}}",
                      "b": "300",
                      "o": "number:greater"
                    }
                  ]
                ]
              },
              "mapper": {
                "status": "401",
                "body": "signature did not verify",
                "headers": []
              },
              "metadata": {
                "designer": {
                  "x": 600,
                  "y": 150
                }
              }
            }
          ]
        }
      ]
    }
  ],
  "metadata": {
    "instant": true,
    "version": 1,
    "scenario": {
      "roundtrips": 1,
      "maxErrors": 3,
      "autoCommit": true,
      "autoCommitTriggerLast": true,
      "sequential": false,
      "slots": null,
      "confidential": true,
      "dataloss": false,
      "dlq": false,
      "freshVariables": false
    },
    "designer": {
      "orphans": []
    }
  }
}
