![]() |
VOOZH | about |
dotnet add package Clerk.Net.DependencyInjection --version 1.15.0
NuGet\Install-Package Clerk.Net.DependencyInjection -Version 1.15.0
<PackageReference Include="Clerk.Net.DependencyInjection" Version="1.15.0" />
<PackageVersion Include="Clerk.Net.DependencyInjection" Version="1.15.0" />Directory.Packages.props
<PackageReference Include="Clerk.Net.DependencyInjection" />Project file
paket add Clerk.Net.DependencyInjection --version 1.15.0
#r "nuget: Clerk.Net.DependencyInjection, 1.15.0"
#:package Clerk.Net.DependencyInjection@1.15.0
#addin nuget:?package=Clerk.Net.DependencyInjection&version=1.15.0Install as a Cake Addin
#tool nuget:?package=Clerk.Net.DependencyInjection&version=1.15.0Install as a Cake Tool
Clerk.Net: Clerk API Client generated with Kiota from Clerk's OpenAPI spec. Compatible with .NET 6+ and .NET Framework 4.7.2+.
Clerk.Net.DependencyInjection: Extensions to register the ClerkApiClient into your DI container. Compatible with .NET 6+.
Clerk.Net.AspNetCore.Security: Clerk Authentication support for ASP.NET Core API. Compatible with .NET 8+.
These libraries are configured as Native AOT compatible for .NET 8+ consumers.
Caution: As the Clerk OpenAPI spec is constantly changing, the core Clerk.Net library does not follow usual SemVer rules, with minor releases usually containing breaking changes. Major releases are only used for breaking changes at the framework level, not for codegen output.
Make sure to add your SecretKey to your application configuration, ideally via the dotnet secrets manager.
Install Clerk.Net.DependencyInjection from Nuget or via the .NET CLI:
dotnet add package Clerk.Net.DependencyInjection
builder.Services.AddClerkApiClient(config =>
{
config.SecretKey = builder.Configuration["Clerk:SecretKey"]!;
});
ClerkApiClient in your servicespublic class MyBackgroundWorker : BackgroundService
{
private readonly ClerkApiClient _clerkApiClient;
public MyBackgroundWorker(ClerkApiClient clerkApiClient)
{
_clerkApiClient = clerkApiClient;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
var invites = await _clerkApiClient.Organizations["org_abc1234"].Invitations.GetAsync(x =>
{
x.QueryParameters.Status = "pending";
});
}
}
If you want to use the client by itself, install Clerk.Net and call ClerkApiClientFactory.Create, passing in your secret key.
The returned client should be treated as a singleton and created once for the lifetime of your application.
If you need to configure the underlying HttpClient used by the client, you can do in one of two ways:
IHttpClientBuilder returned by AddClerkApiClient.HttpClient instance to ClerkApiClientFactory.CreateThis package applies Kiota's default handlers which enables automated retries when hitting Clerk's rate limits. No additional configuration is required.
For unit testing, see Unit testing Kiota API clients.
You should have a new or existing ASP.NET Core application created before continuing.
Install Clerk.Net.AspNetCore.Security from Nuget or via the .NET CLI:
dotnet add package Clerk.Net.AspNetCore.Security
AddClerkAuthentication within your authentication builder, passing in an Authority - the Frontend URI of your Clerk instance - and an AuthorizedParty - the Frontend URL of your application:builder.Services.AddAuthentication(ClerkAuthenticationDefaults.AuthenticationScheme)
.AddClerkAuthentication(x =>
{
x.Authority = builder.Configuration["Clerk:Authority"]!;
x.AuthorizedParty = builder.Configuration["Clerk:AuthorizedParty"]!;
});
builder.Services.AddAuthorizationBuilder()
.SetFallbackPolicy(new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build());
This authentication middleware is compatible with both cross-origin & same-origin requests.
This package is light on options at the moment - Please open an issue if there's something you'd like to be able to configure.
Note: This supports authentication for a remote client - such as an SPA - communicating with your backend. MVC is not supported (yet)
If you're accepting webhooks from Clerk, you will need to validate the incoming webhook signature. To do this, you'll need to install the Svix package:
dotnet add package Svix
Then, you can use the following code to validate the webhook signature:
[HttpPost("webhook")]
public async Task<IActionResult> ClerkWebhook(IConfiguration configuration)
{
// Retrieve the Clerk webhook secret from the configuration
var clerkWebhookSecret = configuration["Clerk:WebhookSecret"];
// Read the request body
var json = await new StreamReader(HttpContext.Request.Body).ReadToEndAsync();
// Retrieve the Svix headers
var svixId = Request.Headers["svix-id"].ToString();
var svixTimestamp = Request.Headers["svix-timestamp"].ToString();
var svixSignature = Request.Headers["svix-signature"].ToString();
if (string.IsNullOrEmpty(svixId) || string.IsNullOrEmpty(svixTimestamp) || string.IsNullOrEmpty(svixSignature))
{
return BadRequest("Missing headers");
}
// Attempt signature verification with the raw signature
var wh = new Webhook(clerkWebhookSecret);
WebHeaderCollection headers = new WebHeaderCollection
{
{ "svix-id", svixId },
{ "svix-timestamp", svixTimestamp },
{ "svix-signature", svixSignature }
};
Event webhookEvent;
try
{
wh.Verify(json, headers); // Verify doesn't return anything, just verifies the signature and throws if it's invalid
webhookEvent = JsonSerializer.Deserialize<Event>(json); // Deserialize the JSON into an Event object
}
catch (Svix.Exceptions.WebhookVerificationException ex)
{
return BadRequest("Invalid signature");
}
catch (Exception ex)
{
return BadRequest("An error occurred");
}
switch (webhookEvent.Type)
{
case "user.created":
// Handle user created event
break;
case "user.updated":
// Handle user updated event
break;
case "user.deleted":
// Handle user deleted event
break;
default:
return BadRequest("Unhandled event type");
}
return Ok();
}
// Define the Event class to represent the webhook event
public class Event
{
public string? Type { get; set; }
public ClerkUser? Data { get; set; }
}
public class ClerkUser
{
public string Id { get; set; }
public string? ExternalId { get; set; }
[JsonPropertyName("first_name")]
public string? FirstName { get; set; }
[JsonPropertyName("last_name")]
public string? LastName { get; set; }
[JsonPropertyName("email_addresses")]
public List<ClerkEmailAddress> EmailAddresses { get; set; } = new List<ClerkEmailAddress>();
}
public class ClerkEmailAddress
{
[JsonPropertyName("email_address")]
public string? EmailAddress { get; set; }
}
I am not affiliated with nor represent Clerk. All support queries regarding the underlying service should go to Clerk Support.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.15.0 | 61,995 | 6/25/2025 |
| 1.14.0 | 6,031 | 4/21/2025 |
| 1.13.0 | 4,262 | 3/4/2025 |
| 1.12.0 | 3,333 | 2/23/2025 |
| 1.11.0 | 10,119 | 2/8/2025 |
| 1.10.0 | 2,417 | 1/13/2025 |
| 1.9.0 | 1,811 | 1/4/2025 |
| 1.8.0 | 4,487 | 11/26/2024 |
| 1.7.0 | 3,852 | 9/27/2024 |
| 1.6.0 | 8,620 | 7/7/2024 |
| 1.5.0 | 7,058 | 5/1/2024 |
| 1.4.0 | 2,068 | 3/17/2024 |
| 1.3.0 | 992 | 12/18/2023 |
| 1.2.0 | 302 | 11/18/2023 |
| 1.1.0 | 423 | 11/4/2023 |
| 1.0.0 | 194 | 10/30/2023 |
| 0.1.0 | 475 | 10/28/2023 |