Clerk.Webhooks 0.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Clerk.Webhooks --version 0.0.1                
NuGet\Install-Package Clerk.Webhooks -Version 0.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Clerk.Webhooks" Version="0.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Clerk.Webhooks --version 0.0.1                
#r "nuget: Clerk.Webhooks, 0.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Clerk.Webhooks as a Cake Addin
#addin nuget:?package=Clerk.Webhooks&version=0.0.1

// Install Clerk.Webhooks as a Cake Tool
#tool nuget:?package=Clerk.Webhooks&version=0.0.1                

Clerk Extensions

A collection of multiple clerk packages for .NET.

Clerk is adding support for clerk.com to .NET.

Clerk.Webhooks is a simple extension for supporting webhooks from clerk.com.

Clerk

Installing Clerk

Clerk is available as a NuGet package and can be installed as

Install-Package Clerk

or via the .NET Core command line interface:

dotnet add package Clerk

Registering using Dependency Injection

Clerk.Webhooks

Installing Clerk.Webhooks

Clerk.Webhooks is available as a NuGet package and can be installed as

Install-Package Clerk.Webhooks

or via the .NET Core command line interface:

dotnet add package Clerk.Webhooks

Creating Webhook Events

Webhook events are simple data classes whose only purpose is to hold the data from the webhook. The data is automatically deserialized from the webhook request.

Events are custom defined in order to enable better flexibility in case of data changes from the event catalog at clerk.com.

For example, if you would like to have a webhook event for when a user is created, you can create a class like this:

public class UserCreated
{
    public string Id { get; set; }
    
    public string Username { get; set; }
    
    [JsonProperty("first_name")]
    public string FirstName { get; set; }
    
    [JsonProperty("last_name")
    public string LastName { get; set; }
}

Creating Webhook Handlers

using Clerk.Webhooks;

public class UserCreatedWebhookHandler : IWebhookHandler<UserCreated>
{
    public Task HandleAsync(Webhook<UserCreated> webhook, CancellationToken cancellationToken)
    {
        // Do something with the webhook event
    }
}

The webhook handlers works with dependency injection, so you can inject any service you need into the handler by its constructor.

Registering using Dependency Injection

using Clerk.Webhooks;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddClerkWebhooks(webhookBuilder => 
{
    // using predefined event names
    webhookBuilder.AddHandler<UserCreated, UserCreatedWebhookHandler>(@event => @event.User.Created);
    
    // or simply using string
    webhookBuilder.AddHandler<UserCreated, UserCreatedWebhookHandler>("user.created");
});

Adding Validation

using Clerk.Webhooks;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddClerkWebhooks(webhookBuilder => 
{
    webhookBuilder.AddHandler<UserCreated, UserCreatedWebhookHandler>(@event => @event.User.Created);
    
    // Adding signing credentials for webhook validation using svix under the hood
    webhookBuilder.AddSigningSecret("signing-secret");
});

Using the middleware

In order to enable request to the webhook endpoint, you need to add the middleware to the request pipeline.

By default, it uses the route prefix '/clerk', but you can change it to whatever you want.

Example using the default route prefix:

using Clerk.Webhooks;

app = builder.build();

app.UseClerkWebhooks();

Example using a custom route prefix:

using Clerk.Webhooks;

app = builder.build();

app.UseClerkWebhooks(options => 
{
    options.RoutePrefix = "/my-webhook-endpoint";
});
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.2 630 9/22/2023
0.0.1 504 9/22/2023
0.0.0-alpha.1 77 9/22/2023