Soenneker.Blazor.Turnstile
4.0.2807
Prefix Reserved
dotnet add package Soenneker.Blazor.Turnstile --version 4.0.2807
NuGet\Install-Package Soenneker.Blazor.Turnstile -Version 4.0.2807
<PackageReference Include="Soenneker.Blazor.Turnstile" Version="4.0.2807" />
<PackageVersion Include="Soenneker.Blazor.Turnstile" Version="4.0.2807" />
<PackageReference Include="Soenneker.Blazor.Turnstile" />
paket add Soenneker.Blazor.Turnstile --version 4.0.2807
#r "nuget: Soenneker.Blazor.Turnstile, 4.0.2807"
#:package Soenneker.Blazor.Turnstile@4.0.2807
#addin nuget:?package=Soenneker.Blazor.Turnstile&version=4.0.2807
#tool nuget:?package=Soenneker.Blazor.Turnstile&version=4.0.2807
Soenneker.Blazor.Turnstile
Renders a Cloudflare Turnstile widget in Blazor and exposes its token, expiration, error, reset, and removal lifecycle.
Installation
dotnet add package Soenneker.Blazor.Turnstile
Registration
using Soenneker.Blazor.Turnstile.Registrars;
builder.Services.AddTurnstileInteropAsScoped();
Render a widget
@using Soenneker.Blazor.Turnstile
@using Soenneker.Blazor.Turnstile.Options
<Turnstile Options="_options"
OnCallback="HandleToken"
OnExpiredCallback="HandleExpiration"
OnErrorCallback="HandleError" />
@code {
private readonly TurnstileOptions _options = new()
{
SiteKey = "your-site-key",
Action = "sign-in"
};
private Task HandleToken(string token)
{
if (!string.IsNullOrEmpty(token))
{
// Send the token to a trusted server for Siteverify validation.
}
return Task.CompletedTask;
}
private Task HandleExpiration(string _) => Task.CompletedTask;
private Task HandleError(string message) => Task.CompletedTask;
}
OnCallback and TokenChanged are raised when a token is issued and again with a cleared value after expiration or an error. OnExpiredCallback and OnErrorCallback provide the corresponding reason. The component's Token and WidgetId properties expose the current values.
The browser token is not proof that a request is legitimate. Send it to a trusted server and validate it with Cloudflare's Siteverify API before performing the protected operation. Keep the Turnstile secret on the server; never include it in Blazor WebAssembly code or browser configuration.
Manual lifecycle
Set ManualCreate = true when application code needs to control widget creation. After the component has rendered, call Create() and retain its returned widget ID. With automatic creation, use Reset() to request another challenge and Remove() to remove the JavaScript widget.
<Turnstile @ref="_turnstile" Options="_manualOptions" />
@code {
private Turnstile? _turnstile;
private readonly TurnstileOptions _manualOptions = new()
{
SiteKey = "your-site-key",
ManualCreate = true
};
private async Task CreateWidget()
{
if (_turnstile is not null)
await _turnstile.Create();
}
}
Calling Create() before the component's first render throws InvalidOperationException. Calling it again without first removing the widget returns null. The component disposes its .NET reference when it leaves the render tree; the scoped interop service is owned by dependency injection.
See Cloudflare's client-side rendering documentation for supported widget settings and the Siteverify documentation for server validation.
| 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
- Soenneker.Asyncs.Initializers (>= 4.0.88)
- Soenneker.Blazor.Extensions.EventCallback (>= 4.0.458)
- Soenneker.Blazor.Utils.ResourceLoader (>= 4.0.1728)
- Soenneker.Lepton.Suite (>= 4.0.64)
- Soenneker.Utils.Json (>= 4.0.2669)
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 |
|---|---|---|
| 4.0.2807 | 0 | 9/1/2026 |
| 4.0.2806 | 0 | 9/1/2026 |
| 4.0.2805 | 0 | 8/31/2026 |
| 4.0.2804 | 25 | 8/31/2026 |
| 4.0.2803 | 23 | 8/31/2026 |
| 4.0.2802 | 32 | 8/31/2026 |
| 4.0.2800 | 42 | 8/31/2026 |
| 4.0.2799 | 33 | 8/31/2026 |
| 4.0.2797 | 61 | 8/31/2026 |
| 4.0.2795 | 43 | 8/30/2026 |
| 4.0.2794 | 45 | 8/30/2026 |
| 4.0.2793 | 50 | 8/30/2026 |
| 4.0.2791 | 55 | 8/30/2026 |
| 4.0.2789 | 54 | 8/30/2026 |
| 4.0.2788 | 43 | 8/30/2026 |
| 4.0.2785 | 41 | 8/30/2026 |
| 4.0.2784 | 38 | 8/30/2026 |
| 4.0.2783 | 42 | 8/29/2026 |
| 4.0.2780 | 49 | 8/29/2026 |
| 4.0.2779 | 37 | 8/29/2026 |
Updated NuGet packages