Persilsoft.Turnstile.Server
1.0.4
See the version list below for details.
dotnet add package Persilsoft.Turnstile.Server --version 1.0.4
NuGet\Install-Package Persilsoft.Turnstile.Server -Version 1.0.4
<PackageReference Include="Persilsoft.Turnstile.Server" Version="1.0.4" />
<PackageVersion Include="Persilsoft.Turnstile.Server" Version="1.0.4" />
<PackageReference Include="Persilsoft.Turnstile.Server" />
paket add Persilsoft.Turnstile.Server --version 1.0.4
#r "nuget: Persilsoft.Turnstile.Server, 1.0.4"
#:package Persilsoft.Turnstile.Server@1.0.4
#addin nuget:?package=Persilsoft.Turnstile.Server&version=1.0.4
#tool nuget:?package=Persilsoft.Turnstile.Server&version=1.0.4
Persilsoft.Turnstile.Server
Persilsoft.Turnstile.Server is a backend library that provides a ready-to-use service to verify CAPTCHA tokens using Cloudflare Turnstile.
It eliminates the need to manually call the siteverify endpoint — you just call a method from the injected service.
🚀 Installation
- Install the NuGet package:
dotnet add package Persilsoft.Turnstile.Server
- Register the Turnstile services in your backend:
using Persilsoft.Turnstile.Server.Options;
using Persilsoft.Turnstile.Server;
Action<TurnstileOptions> turnstileOptionsConfigurator = options =>
builder.Configuration.GetRequiredSection(TurnstileOptions.SectionKey).Bind(options);
builder.Services.AddTurnstileServices(turnstileOptionsConfigurator);
🔧 Configuration
Add the following section to your appsettings.json:
"TurnstileOptions": {
"VerifyEndpoint": "https://challenges.cloudflare.com/turnstile/v0/siteverify",
"SecretKey": "YOUR_SECRET_KEY"
}
| Key | Description |
|---|---|
VerifyEndpoint |
The Cloudflare Turnstile API endpoint for verification (keep default). |
SecretKey |
Your private secret key provided by Cloudflare. |
✅ Example Usage
You can inject the TurnstileService into any endpoint or controller to validate the CAPTCHA token sent from your frontend:
Example Minimal API Endpoint
namespace Persilsoft.Turnstile.Server.Tests.Endpoints;
internal static class DemoEndpoints
{
public static WebApplication UseDemoEndpoints(this WebApplication app)
{
app
.MapPost("send", Send)
.Produces(StatusCodes.Status200OK)
.Produces(StatusCodes.Status500InternalServerError)
.WithTags("Turnstile")
.WithName(nameof(Send))
.WithSummary("Send demo data")
.WithDescription("Receives demo data along with a Turnstile token and validates it using Cloudflare SiteVerify.");
return app;
}
private static async Task<IResult> Send(DemoModel dto, TurnstileService service)
{
var isValid = await service.VerifyAsync(dto.CaptchaToken);
if (!isValid)
{
throw new BadHttpRequestException($"Token verification failed.");
}
Console.WriteLine("Save data to the database...");
return TypedResults.Ok();
}
}
Example DTO
public class DemoModel
{
public string Name { get; set; } = string.Empty;
public string CaptchaToken { get; set; } = string.Empty;
}
📜 License
MIT License
✨ Credits
Developed by Persilsoft.
Secure and simplify CAPTCHA verification on the server.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.Http (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
- Persilsoft.Captcha.Abstraction (>= 1.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Persilsoft.Turnstile.Server:
| Package | Downloads |
|---|---|
|
Persilsoft.Captcha.Factory
Backend factory implementation for multiple captcha providers (ReCaptcha v3, Cloudflare Turnstile). Provides automatic endpoint registration (POST /captcha/verify) and dependency injection configuration for ASP.NET Core applications. Works seamlessly with Persilsoft.Recaptcha.Blazor for complete full-stack captcha verification. |
GitHub repositories
This package is not used by any popular GitHub repositories.