简体   繁体   English

Node.js:条纹错误找不到与有效负载的预期签名匹配的签名

[英]Node.js: Stripe error No signatures found matching the expected signature for payload

Error:错误:

"message": "No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe? https://github.com/stripe/stripe-node#webhook-signing ", "message": "没有找到与负载的预期签名匹配的签名。您是否正在传递从 Stripe 收到的原始请求正文? https://github.com/stripe/stripe-node#webhook-signing ",

I've tried req.rawBody , but the same result.我试过req.rawBody ,但结果相同。 I ve also tried all the solutions available on stack overflow and github.我还尝试了堆栈溢出和 github 上可用的所有解决方案。

server.js服务器.js

// use express body parser
app.use(bodyParse.json());

stripe.js条纹.js

router
  .route('/payment/hook')
  .post(bodyParser.raw({
    type: 'application/json'
  }), paymentsController.transactionHook);

paymentsController.js支付控制器.js

transactionHook: async(req, res, next) => {
    const sig = req.headers['stripe-signature'];
    let event;

    try {
      event = await stripe.webhooks.constructEvent(req.body, sig, endpointSecret);

    } catch (err) {
        return res.status(400).json({ message: err.message, detail: err.detail });
      }
  }

Response回复

回复

Using bodyParser.json() will modify the body such that the signatures are not verifiable.使用bodyParser.json()将修改正文,使签名无法验证。 You need to ensure this middleware is not being applied for your webhook /hook endpoint.您需要确保此中间件应用于您的 webhook /hook端点。

One way to do this with Express is to simply define the webhook endpoint before you apply the middleware (in the sequence of building your routes).使用 Express 执行此操作的一种方法是应用中间件之前(按照构建路由的顺序)简单地定义 webhook 端点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 GCP:Stripe webhook 错误:未找到与有效负载的预期签名匹配的签名 - GCP: Stripe webhook error: No signatures found matching the expected signature for payload Stripe webhooks 错误“找不到与有效负载的预期签名匹配的签名” - Stripe webhooks error "No signatures found matching the expected signature for payload" Stripe webhook nodejs remix.run Stripe webhook - 找不到与有效负载的预期签名匹配的签名 - Stripe webhook nodejs remix.run Stripe webhook - No signatures found matching the expected signature for payload 条带构造事件:未找到与有效负载的预期签名匹配的签名。 Javascript,快递 - Stripe Construct Event: No signatures found matching the expected signature for payload. Javascript, Express RegExp与Node.js中的预期模式不匹配 - RegExp not matching expected pattern in Node.js Node.js上的Stripe API错误:没有这样的客户: - Stripe API on Node.js Error: No such customer: 如何在 Node.JS 中将 Json Web 令牌拆分为 Header-Payload-Signature - How to split Json Web Token as Header-Payload-Signature in Node.JS node.js / Swift / Stripe / Webtask在创建时出错 - node.js / Swift / Stripe / Webtask error in creating charge 使用execSync运行Sigcheck(Node.js)的“找不到匹配的文件” - “No Matching Files Found” Running Sigcheck (Node.js) with execSync 在node.js mysql查询中,检查是否找不到匹配项 - In node.js mysql query, check if no matching found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM