Guides & Recipes — Webhooks
L3StableNuGet: v1.0.0Local HEAD: v2.1.0AOT: Full
Verified signing and verification recipes compiled on .NET 10 (ImplicitUsings=disable, Nullable=enable).
Recipe 1: Signing & Constant-Time Verifying a Payload (WebhookSigner)
Section titled “Recipe 1: Signing & Constant-Time Verifying a Payload (WebhookSigner)”using System;using EricksonLopez.Webhooks;
namespace Example.WebhooksQuickStart;
public static class WebhookSigningRecipe{ public static bool SignAndVerify(string webhookSecret) { const string payload = "{\"event\":\"invoice.paid\"}"; long timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
string signature = WebhookSigner.ComputeSignature(webhookSecret, timestamp, payload); return WebhookSigner.VerifySignature( webhookSecret, timestamp, payload, signature, WebhookReceiverProtocol.EricksonLopez); }}Recipe 2: Outbound-Only DI Registration with AddWebhooks
Section titled “Recipe 2: Outbound-Only DI Registration with AddWebhooks”using System;using EricksonLopez.Webhooks;using Microsoft.Extensions.DependencyInjection;
namespace Example.WebhooksQuickStart;
public static class OutboundSenderRecipe{ public static ServiceProvider BuildSenderProvider() { var services = new ServiceCollection(); services.AddLogging(); services.AddWebhooks(options => { options.Timeout = TimeSpan.FromSeconds(10); options.EnableSsrfProtection = true; options.MaxPayloadSizeBytes = 1024 * 1024; options.Protocol = WebhookSenderProtocol.EricksonLopez; });
return services.BuildServiceProvider( new ServiceProviderOptions { ValidateOnBuild = true, ValidateScopes = true }); }}