Ir al contenido

Buscar en el Ecosistema EricksonLopez.*

Escribe el nombre de una librería, ID de paquete NuGet, tipo .NET o concepto arquitectónico para buscar en el portal.

Primeros Pasos con EricksonLopez.Webhooks

Instala EricksonLopez.Webhooks y EricksonLopez.Webhooks.AspNetCore (1.0.0 en NuGet).

dotnet add package EricksonLopez.Webhooks --version 1.0.0
Ventana de terminal
dotnet add package EricksonLopez.Webhooks.AspNetCore --version 1.0.0
dotnet add package EricksonLopez.Webhooks.Redis --version 1.0.0

Nota de Publicación: EricksonLopez.Webhooks.PaymentGateways existe únicamente en el workspace local 2.1.0 y no está publicado en NuGet.org.

Pasa la clave secreta desde configuración o variables de entorno (ELS0003 detecta secretos literales en código):

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.");
}
}
}