BasicCaptcha 1.2.0
dotnet add package BasicCaptcha --version 1.2.0
NuGet\Install-Package BasicCaptcha -Version 1.2.0
<PackageReference Include="BasicCaptcha" Version="1.2.0" />
<PackageVersion Include="BasicCaptcha" Version="1.2.0" />
<PackageReference Include="BasicCaptcha" />
paket add BasicCaptcha --version 1.2.0
#r "nuget: BasicCaptcha, 1.2.0"
#:package BasicCaptcha@1.2.0
#addin nuget:?package=BasicCaptcha&version=1.2.0
#tool nuget:?package=BasicCaptcha&version=1.2.0
BasicCAPTCHA
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
- Install Nuget Package
Install-Package BasicCaptcha -Version 1.2.0
- 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")));
- 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 | Versions 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. |
-
.NETStandard 2.1
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
- Newtonsoft.Json (>= 13.0.3)
-
net7.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.