Turnstile.Net
1.0.0
dotnet add package Turnstile.Net --version 1.0.0
NuGet\Install-Package Turnstile.Net -Version 1.0.0
<PackageReference Include="Turnstile.Net" Version="1.0.0" />
paket add Turnstile.Net --version 1.0.0
#r "nuget: Turnstile.Net, 1.0.0"
// Install Turnstile.Net as a Cake Addin #addin nuget:?package=Turnstile.Net&version=1.0.0 // Install Turnstile.Net as a Cake Tool #tool nuget:?package=Turnstile.Net&version=1.0.0
Turnstile.Net
Turnstile.Net is a .Net library that provides you method to validate your form using Cloudflare Turnstile captcha.
How to use it
Provide the key
Just provide in your configuration (either on appsettings.json/appsettings.development.json or Azure KeyVault) with the key :
"Turnstile" : {
"SiteKey": "YOUR_SITE_KEY",
"SecretKey": "YOUR_SECRET_KEY"
}
Configure client side rendering
Don't forget to add the cloudflare javascript script to your page in order to get the captcha shown on your page.
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js"></script>
Use it in your project
First, activate the services from your Program.cs
file
builder.Services.AddTurnstile();
Then add the dependecy to your controller.
public class YourController : Controller {
private readonly ITurnstileService _turnstileService;
public YourController(ITurnstileService turnstileService) {
_turnstileService = turnstileService;
}
}
And finally you can handle it on your post action method :
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult FormHandler(YourModel model) {
if(!ModelState.IsValid) {
return View(model);
}
var captchaFormToken = Request.Form["cf-turnstile-response"].ToString();
var isFormValid = _turnstileService.ValidateCaptchaAsync(captchaFormToken);
if(isFormValid) {
// Do your stuff here
}
return View(model);
}
Same principle applies to Razor Pages or Blazor.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
-
net8.0
- Microsoft.Extensions.Configuration (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.Logging (>= 8.0.0)
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 |
---|---|---|
1.0.0 | 487 | 2/22/2024 |