GkCaptcha 0.1.0

dotnet add package GkCaptcha --version 0.1.0
                    
NuGet\Install-Package GkCaptcha -Version 0.1.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="GkCaptcha" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GkCaptcha" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="GkCaptcha" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add GkCaptcha --version 0.1.0
                    
#r "nuget: GkCaptcha, 0.1.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.
#:package GkCaptcha@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=GkCaptcha&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=GkCaptcha&version=0.1.0
                    
Install as a Cake Tool

gkCAPTCHA .NET SDK

Official .NET client for gkCAPTCHA — an AI-resistant CAPTCHA built for PDPL compliance.

Packages

Package NuGet Description
GkCaptcha dotnet add package GkCaptcha Core client (zero runtime dependencies)
GkCaptcha.AspNetCore dotnet add package GkCaptcha.AspNetCore ASP.NET Core integration: DI, middleware, attribute, tag helper

Requirements

  • .NET 8.0 or later

Quick Start — Standalone .NET

using GkCaptcha;

var client = new GkCaptchaClient(new GkCaptchaOptions
{
    SecretKey = "your_secret_key",   // or set GKCAPTCHA_SECRET_KEY env var
    SiteKey   = "your_site_key",     // or set GKCAPTCHA_SITE_KEY env var
});

var result = await client.VerifyTokenAsync(token);

if (result.FailOpen)
{
    // API was unreachable — fail-open: request allowed through (safe default)
    Console.WriteLine("Fail-open: allowing request");
}
else if (result.Success)
{
    Console.WriteLine($"Human verified (score: {result.Score})");
}
else
{
    Console.WriteLine($"Bot detected: {result.Error} ({result.ReasonCode})");
}

Fail-Open Behavior

By default, if the gkCAPTCHA API is unreachable after 1 retry, the client returns VerifyTokenResponse { Success = true, FailOpen = true } — your application continues rather than blocking legitimate users during an outage.

To fail closed (reject on API error):

var client = new GkCaptchaClient(new GkCaptchaOptions
{
    SecretKey  = "...",
    SiteKey    = "...",
    FailClosed = true,  // throw GkCaptchaException on network error
});

ASP.NET Core Quick Start

1. Register in Program.cs

using GkCaptcha.AspNetCore;

builder.Services.AddGkCaptcha(opts =>
{
    opts.SecretKey = builder.Configuration["GkCaptcha:SecretKey"];
    opts.SiteKey   = builder.Configuration["GkCaptcha:SiteKey"];
});

2. appsettings.json

{
  "GkCaptcha": {
    "SecretKey": "your_secret_key",
    "SiteKey":   "your_site_key"
  }
}

Middleware

Protect entire path prefixes. All requests to those paths require a valid CAPTCHA token.

app.UseGkCaptcha(opts =>
{
    opts.Paths.Add("/login");
    opts.Paths.Add("/register");
});

When no paths are configured, all requests are protected.


[RequireCaptcha] Attribute

Apply to MVC controllers or actions:

using GkCaptcha.AspNetCore;

[HttpPost]
[RequireCaptcha]
public IActionResult Login([FromForm] LoginModel model)
{
    // CAPTCHA already verified — proceed with login
    return Ok();
}

Returns HTTP 400 if the token is missing, HTTP 403 if verification fails.


Minimal API — .RequireGkCaptcha()

app.MapPost("/api/contact", (ContactRequest req) => Results.Ok())
   .RequireGkCaptcha();

Razor Tag Helper

Register in _ViewImports.cshtml:

@addTagHelper *, GkCaptcha.AspNetCore

Use in Razor views:

<form method="post">
    <gk-captcha site-key="@Model.SiteKey" theme="dark" />
    <button type="submit">Submit</button>
</form>

Renders:

<gk-captcha sitekey="pk_live_..." theme="dark"></gk-captcha>
<script src="https://cdn.gatekeeper.sa/gk-captcha.js" async defer></script>

Attributes: site-key (required), theme (light/dark, default light), widget-url (override CDN URL).


Token Sources

The SDK reads the CAPTCHA token from (in order):

  1. Form field: gk-captcha-token (only for application/x-www-form-urlencoded or multipart/form-data requests)
  2. HTTP header: X-Gk-Captcha-Token

Your frontend widget automatically submits the token. For API clients, pass the token in the header.


Configuration Reference

Option Type Default Description
SecretKey string env: GKCAPTCHA_SECRET_KEY Your site secret key
SiteKey string env: GKCAPTCHA_SITE_KEY Your public site key
ApiUrl string https://gkcaptcha.gatekeeper.sa API base URL
Timeout TimeSpan 5 seconds Per-request timeout
MaxRetries int 1 Network retries before fail-open/closed
FailClosed bool false Throw on API error instead of fail-open

Testing

Inject IGkCaptchaClient in your tests without any mocking library:

private sealed class MockCaptcha(bool success) : IGkCaptchaClient
{
    public Task<VerifyTokenResponse> VerifyTokenAsync(
        string token, VerifyOptions? opts = null, CancellationToken ct = default)
        => Task.FromResult(new VerifyTokenResponse { Success = success });
}

// Register in test DI:
services.AddSingleton<IGkCaptchaClient>(new MockCaptcha(success: true));

License

MIT — see LICENSE.

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.  net9.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on GkCaptcha:

Package Downloads
GkCaptcha.AspNetCore

gkCAPTCHA ASP.NET Core integration - middleware, tag helper, DI registration

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 134 3/26/2026