"The signature for the webhook is not present in the Stripe-Signature header."

"The signature for the webhook is not present in the Stripe-Signature header."

我正在使用来自 NuGet 的 Stripe.net SDK。我总是从 StripeEventUtility.ConstructEvent 方法中得到异常。 WebHook 密钥正确,请求 Header 包含“Stripe-Signature”密钥。

我正确地接收了来自 Webhook 测试程序实用程序的传入数据(将 nGrok 与 Visual Studio 结合使用)。

我试图操纵来自 Stripe 的传入数据(Jobject、字符串、序列化...)。负载签名可能会导致一些问题。

有没有人遇到同样的问题?

Webhook tester utility

您指的是 Stripe CLI,使用 listen 命令并转发到您的端点吗?如果是这样,请务必使用 listen 命令返回的 webhook 密码,而不是与仪表板上配置的端点相关的密码。

此问题的另一个主要来源是请求正文的变化。签名验证严格取决于能否访问请求的原始正文,包括原始空格等。

查看 .NET 中访问原始请求正文的 webhook 端点的示例实现:https://github.com/stripe-samples/accept-a-payment/blob/main/custom-payment-flow/server/dotnet/Controllers/PaymentsController.cs#L86