Skip to content

Search EricksonLopez.* Ecosystem

Type a library name, NuGet package ID, .NET type, or architectural concept to search across the portal.

Getting Started with EricksonLopez.Webhooks

Install EricksonLopez.Webhooks and EricksonLopez.Webhooks.AspNetCore (1.0.0 on NuGet).

dotnet add package EricksonLopez.Webhooks --version 1.0.0
Terminal window
dotnet add package EricksonLopez.Webhooks.AspNetCore --version 1.0.0
dotnet add package EricksonLopez.Webhooks.Redis --version 1.0.0

Publication Note: EricksonLopez.Webhooks.PaymentGateways exists only in local 2.1.0 HEAD and is not published on NuGet.org.

Pass your webhook secret from configuration or environment variables (ELS0003 flags hardcoded secret strings):

using System;
using EricksonLopez.Webhooks;
using EricksonLopez.Webhooks.AspNetCore;
using Microsoft.Extensions.DependencyInjection;
namespace Example.WebhooksQuickStart;
public static class WebhooksUsage
{
public static void Register(string webhookSecret)
{
var services = new ServiceCollection();
services.AddLogging();
services.AddWebhooks(options =>
{
options.Timeout = TimeSpan.FromSeconds(10);
options.EnableSsrfProtection = true;
options.Protocol = WebhookSenderProtocol.EricksonLopez;
});
services.AddWebhookReceiver(options =>
{
options.RoutePath = "/api/webhooks/incoming";
options.SecretKey = webhookSecret;
});
services.AddInMemoryReplayDetector(TimeSpan.FromMinutes(5));
using var provider = services.BuildServiceProvider(
new ServiceProviderOptions { ValidateOnBuild = true, ValidateScopes = true });
var sender = provider.GetRequiredService<IWebhookSender>();
var validator = provider.GetRequiredService<IWebhookValidator>();
if (sender is null || validator is null)
{
throw new InvalidOperationException("Webhook services were not registered.");
}
}
}