{
  "name": "Verify signed webhook (HMAC-SHA256, raw body) - The Automated Shop",
  "nodes": [
    {
      "id": "we428c752",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        0,
        0
      ],
      "parameters": {
        "httpMethod": "POST",
        "path": "signed-event",
        "options": {
          "rawBody": true
        },
        "responseMode": "responseNode"
      },
      "webhookId": "c6d84d6f-1ec4-4534-a251-32b094cc61b9"
    },
    {
      "id": "cr1",
      "name": "HMAC of raw body",
      "type": "n8n-nodes-base.crypto",
      "typeVersion": 2,
      "position": [
        260,
        0
      ],
      "parameters": {
        "action": "hmac",
        "type": "SHA256",
        "encoding": "hex",
        "binaryData": true,
        "binaryPropertyName": "data",
        "dataPropertyName": "expected_signature"
      },
      "credentials": {
        "crypto": {
          "id": "",
          "name": "Webhook signing secret"
        }
      }
    },
    {
      "id": "if1",
      "name": "Signature matches?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        520,
        0
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $json.expected_signature }}",
              "rightValue": "={{ ($('Webhook').item.json.headers['x-signature'] || '').replace(/^sha256=/, '') }}",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "r200",
      "name": "Accept (200)",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.4,
      "position": [
        780,
        -100
      ],
      "parameters": {
        "respondWith": "json",
        "responseBody": "={\"ok\": true}",
        "options": {
          "responseCode": 200
        }
      }
    },
    {
      "id": "r401",
      "name": "Reject (401)",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.4,
      "position": [
        780,
        100
      ],
      "parameters": {
        "respondWith": "json",
        "responseBody": "={\"ok\": false, \"error\": \"bad signature\"}",
        "options": {
          "responseCode": 401
        }
      }
    },
    {
      "id": "body1",
      "name": "Parse event",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1040,
        -100
      ],
      "parameters": {
        "mode": "raw",
        "jsonOutput": "={{ JSON.stringify({ event: $('Webhook').item.json.body }) }}",
        "options": {}
      }
    },
    {
      "id": "n96f98381",
      "name": "Handle the event here",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1300,
        0
      ],
      "parameters": {}
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "HMAC of raw body",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HMAC of raw body": {
      "main": [
        [
          {
            "node": "Signature matches?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Signature matches?": {
      "main": [
        [
          {
            "node": "Accept (200)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Reject (401)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Accept (200)": {
      "main": [
        [
          {
            "node": "Parse event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse event": {
      "main": [
        [
          {
            "node": "Handle the event here",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false
  }
}