BasicCaptcha 1.2.0

dotnet add package BasicCaptcha --version 1.2.0
                    
NuGet\Install-Package BasicCaptcha -Version 1.2.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="BasicCaptcha" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BasicCaptcha" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="BasicCaptcha" />
                    
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 BasicCaptcha --version 1.2.0
                    
#r "nuget: BasicCaptcha, 1.2.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 BasicCaptcha@1.2.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=BasicCaptcha&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=BasicCaptcha&version=1.2.0
                    
Install as a Cake Tool

BasicCAPTCHA

Run unit tests

Overview

I created this library as I found that other NuGet libraries seem to focus a lot on integrating with ASP's bespoke functionality rather than just verifying tokens. I originally created it to use on an Azure Functions API which uses dependency injection, but you can use it anywhere.

Basic library for verifying CAPTCHA tokens. Currently only supports Google ReCAPTCHA (V3/V2) which use the 'siteverify' endpoint to verify tokens, but I'm open to accepting pull requests for other providers if required.

You can also extend the library to support other providers by extending the BaseProvider class and implementing the VerifyToken method.

Getting Started

  1. Install Nuget Package
Install-Package BasicCaptcha -Version 1.2.0
  1. Register the service with your secret key in your startup file, here I'm using an environment variable. Don't hardcode this secret if possible!
builder.Services.AddHttpClient();  
builder.Services.AddCaptcha(new GoogleRecaptchaProvider(Environment.GetEnvironmentVariable("GOOGLE_RECAPTCHA_SECRET")));  
  1. Use the service wherever you require it...
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using BasicCaptcha.Contracts;

namespace Example.Controllers;

public sealed class ExampleController : Controller
{  
  private readonly ICaptchaService _captchaService;  

  public ExampleController(ICaptchaService captchaService)  
  {  
      _captchaService = captchaService;  
  }  
    
  public async Task<IActionResult> Example(string token)  
  {  
      var valid = await _captchaService.VerifyTokenAsync(token);
      return valid ? Ok() : BadRequest();  
  }  
}  

Dummy Provider

If you're doing development work, especially API development work, you probably don't want to have to fill out a CAPTCHA challenge every time you hit your endpoint. So you can use the dummy provider to bypass the CAPTCHA challenge.

To use this you can use the dummy provider

builder.Services.AddHttpClient();  
builder.Services.AddCaptcha(new DummyRecaptchaProvider());  

If you wish to force a failure, you can pass fail as the token (case-insensitive) and the VerifyToken method will always return false instead.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.2.0 333 7/13/2023
1.1.1 181 7/13/2023
1.1.0 212 7/13/2023
1.0.3 508 4/22/2022
1.0.2 458 4/22/2022
1.0.1 454 4/22/2022
1.0.0 489 4/12/2021