Turnstile.Net 1.0.0

dotnet add package Turnstile.Net --version 1.0.0                
NuGet\Install-Package Turnstile.Net -Version 1.0.0                
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="Turnstile.Net" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Turnstile.Net --version 1.0.0                
#r "nuget: Turnstile.Net, 1.0.0"                
#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 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 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. 
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
1.0.0 487 2/22/2024