validateWebhookSignature()
验证通过 webhook 端点接收到的签名是否真实。如果验证失败,将抛出错误。
🌐 Validates that the signature that was received by a webhook endpoint is authentic. If the validation fails, an error is thrown.
应用编程接口
🌐 API
该函数接受一个包含三个键值对的对象:
🌐 The function accepts an object with three key-value pairs:
secret
与传递给 renderMediaOnLambda() 的 webhook 选项的 webhook 密钥相同。
🌐 The same webhook secret that was passed to renderMediaOnLambda()'s webhook options.
body
被端点接收的主体——接受一个解析后的 JSON 对象,而不是 string。
🌐 The body that was received by the endpoint - takes a parsed JSON object, not a string.
signatureHeader
从端点接收到的请求中的 X-Remotion-Signature 头。
🌐 The X-Remotion-Signature header from the request that was received by the endpoint.
示例
🌐 Example
在下面的 Next.JS webhook 端点中,如果签名与预期的签名不匹配或缺失,将会抛出错误。
🌐 In the following Next.JS webhook endpoint, an error gets thrown if the signature does not match the one expected one or is missing..
pages/api/webhook.tsimport {validateWebhookSignature ,WebhookPayload } from '@remotion/lambda/client'; export default async functionhandler (req :NextApiRequest ,res :NextApiResponse ) {validateWebhookSignature ({secret :process .env .WEBHOOK_SECRET as string,body :req .body ,signatureHeader :req .headers ['x-remotion-signature'] as string, }); // If code reaches this path, the webhook is authentic. constpayload =req .body asWebhookPayload ; if (payload .type === 'success') { // ... } else if (payload .type === 'timeout') { // ... }res .status (200).json ({success : true, }); }
请参见 Webhooks 了解 Express 示例。
🌐 See Webhooks for an Express example.
另请参阅
🌐 See also