验证 GitHub Webhook 密钥

中级

这是一个Content Creation、Multimodal AI领域的自动化工作流,包含 11 个节点。主要使用 If、Crypto、Github、Webhook、StopAndError 等节点。 使用 HMAC256 签名验证保护 GitHub Webhooks

前置要求
  • GitHub Personal Access Token
  • HTTP Webhook 端点(n8n 会自动生成)
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "vhGeQ894g6ZrApne",
  "meta": {
    "instanceId": "387143f3437214efa36d378126c48f0e9f1f4a29675a99d88a37edd8b872d0b0",
    "templateCredsSetupCompleted": true
  },
  "name": "验证 GitHub Webhook 密钥",
  "tags": [],
  "nodes": [
    {
      "id": "d46d3d2c-39ae-4e7d-9c27-a47ea2f36cc2",
      "name": "响应 200 OK",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        752,
        -80
      ],
      "parameters": {
        "options": {
          "responseCode": 200
        },
        "respondWith": "noData"
      },
      "typeVersion": 1.4
    },
    {
      "id": "6cfacb26-0472-4021-9060-62a5b67e3c8b",
      "name": "响应 401 未授权",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        752,
        96
      ],
      "parameters": {
        "options": {
          "responseCode": 401
        },
        "respondWith": "noData"
      },
      "typeVersion": 1.4
    },
    {
      "id": "e8683705-1757-4f3a-a332-9c68ee505cf8",
      "name": "GitHub Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -96,
        0
      ],
      "webhookId": "304485a2-62c6-454d-8237-d7e48569735f",
      "parameters": {
        "path": "github-test",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "typeVersion": 2.1
    },
    {
      "id": "4dea131c-2c72-4d67-a8b8-c9aff6c4ac1a",
      "name": "计算 HMAC256",
      "type": "n8n-nodes-base.crypto",
      "position": [
        208,
        0
      ],
      "parameters": {
        "type": "SHA256",
        "value": "={{ JSON.stringify($json.body) }}",
        "action": "hmac",
        "secret": "=your_github_secret_here",
        "dataPropertyName": "=signature-256"
      },
      "typeVersion": 1
    },
    {
      "id": "98a2788a-081e-4f59-8845-08d28fb7f9c9",
      "name": "验证 HMAC256",
      "type": "n8n-nodes-base.if",
      "position": [
        416,
        0
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "80e6b785-15d2-4f32-94e6-fcd7942fb2e4",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json['signature-256'] }}",
              "rightValue": "={{ $json.headers['x-hub-signature-256'].split('=').pop() }}"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "d61e551c-0b5a-4b3a-a7de-035d0be495d0",
      "name": "便签 6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        160,
        -368
      ],
      "parameters": {
        "color": 7,
        "width": 520,
        "height": 780,
        "content": "## 1. 计算 Webhook 正文的 HMAC256 并与提供的 HMAC256 值进行比较"
      },
      "typeVersion": 1
    },
    {
      "id": "b075a191-631f-4145-a585-00fea49e07f1",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        704,
        -368
      ],
      "parameters": {
        "color": 7,
        "width": 520,
        "height": 780,
        "content": "## 2. 向 GitHub 服务器确认消息有效性"
      },
      "typeVersion": 1
    },
    {
      "id": "390aeb5b-8bcc-4591-bea8-550c5f1be475",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1248,
        -368
      ],
      "parameters": {
        "color": 7,
        "width": 520,
        "height": 780,
        "content": "## 3. 继续工作流的其余部分..."
      },
      "typeVersion": 1
    },
    {
      "id": "41239b01-a07c-4dc2-a169-c1aca34b32df",
      "name": "获取仓库资料",
      "type": "n8n-nodes-base.github",
      "position": [
        1408,
        -80
      ],
      "webhookId": "e608e4db-519a-4372-9d6b-825ab78d3b6e",
      "parameters": {
        "owner": {
          "__rl": true,
          "mode": "url",
          "value": "={{ $json.body.repository.owner.html_url }}"
        },
        "resource": "repository",
        "operation": "getProfile",
        "repository": {
          "__rl": true,
          "mode": "url",
          "value": "={{ $json.body.repository.html_url }}"
        }
      },
      "credentials": {
        "githubApi": {
          "id": "TncaZr1QfO3U3Dvz",
          "name": "GitHub account"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "74a5a28c-2bd0-42e8-961b-2ef35d0c1b44",
      "name": "停止并报错",
      "type": "n8n-nodes-base.stopAndError",
      "position": [
        976,
        96
      ],
      "parameters": {
        "errorMessage": "HMAC256 signature doesn't match provided signature. Make sure that the GitHub webhook secret is identical to the secret stored in the 'Compute HMAC256' node. "
      },
      "typeVersion": 1
    },
    {
      "id": "97a22928-bfe7-433e-b989-9ae5799edcd0",
      "name": "便签 7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -656,
        -464
      ],
      "parameters": {
        "width": 460,
        "height": 1280,
        "content": "## 使用 HMAC256 验证 GitHub webhook 签名"
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "pinData": {},
  "settings": {
    "timezone": "America/Denver",
    "callerPolicy": "workflowsFromSameOwner",
    "executionOrder": "v1"
  },
  "versionId": "0ec47ca5-fa4e-43f3-a827-85fe278f10af",
  "connections": {
    "GitHub Webhook": {
      "main": [
        [
          {
            "node": "Compute HMAC256",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Respond 200 OK": {
      "main": [
        [
          {
            "node": "Get the profile of a repository",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compute HMAC256": {
      "main": [
        [
          {
            "node": "Validate HMAC256",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate HMAC256": {
      "main": [
        [
          {
            "node": "Respond 200 OK",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Respond 401 Unauthorized",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Respond 401 Unauthorized": {
      "main": [
        [
          {
            "node": "Stop and Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get the profile of a repository": {
      "main": [
        []
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

这是一个中级难度的工作流,适用于Content Creation、Multimodal AI等场景。适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
中级
节点数量11
分类2
节点类型7
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

外部链接
在 n8n.io 上查看 →

分享此工作流