Getting Started with EricksonLopez.Webhooks
L3StableNuGet: v1.0.0Local HEAD: v2.1.0AOT: Full
Install EricksonLopez.Webhooks and EricksonLopez.Webhooks.AspNetCore (1.0.0 on NuGet).
dotnet add package EricksonLopez.Webhooks --version 1.0.0<PackageReference Include="EricksonLopez.Webhooks" Version="1.0.0" /><PackageVersion Include="EricksonLopez.Webhooks" Version="1.0.0" />dotnet add package EricksonLopez.Webhooks.AspNetCore --version 1.0.0dotnet add package EricksonLopez.Webhooks.Redis --version 1.0.0Publication Note:
EricksonLopez.Webhooks.PaymentGatewaysexists only in local2.1.0HEAD and is not published on NuGet.org.
Quick Start: Outbound Sender & Inbound Receiver (ValidateOnBuild=true)
Section titled “Quick Start: Outbound Sender & Inbound Receiver (ValidateOnBuild=true)”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."); } }}