Persilsoft.Turnstile.Server
1.0.2
dotnet add package Persilsoft.Turnstile.Server --version 1.0.2
NuGet\Install-Package Persilsoft.Turnstile.Server -Version 1.0.2
<PackageReference Include="Persilsoft.Turnstile.Server" Version="1.0.2" />
<PackageVersion Include="Persilsoft.Turnstile.Server" Version="1.0.2" />
<PackageReference Include="Persilsoft.Turnstile.Server" />
paket add Persilsoft.Turnstile.Server --version 1.0.2
#r "nuget: Persilsoft.Turnstile.Server, 1.0.2"
#addin nuget:?package=Persilsoft.Turnstile.Server&version=1.0.2
#tool nuget:?package=Persilsoft.Turnstile.Server&version=1.0.2
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 | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net9.0
- Microsoft.Extensions.Options (= 9.0.4)
- Persilsoft.Result (= 1.0.2)
- Persilsoft.Turnstile.Shared (= 1.0.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Persilsoft.Turnstile.Server:
Package | Downloads |
---|---|
Persilsoft.Membership.Core
Contains services, interactors, presenters and controllers for membership backend projects |
GitHub repositories
This package is not used by any popular GitHub repositories.