Persilsoft.Recaptcha.Server 1.0.11

dotnet add package Persilsoft.Recaptcha.Server --version 1.0.11
NuGet\Install-Package Persilsoft.Recaptcha.Server -Version 1.0.11
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="Persilsoft.Recaptcha.Server" Version="1.0.11" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Persilsoft.Recaptcha.Server --version 1.0.11
#r "nuget: Persilsoft.Recaptcha.Server, 1.0.11"
#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 Persilsoft.Recaptcha.Server as a Cake Addin
#addin nuget:?package=Persilsoft.Recaptcha.Server&version=1.0.11

// Install Persilsoft.Recaptcha.Server as a Cake Tool
#tool nuget:?package=Persilsoft.Recaptcha.Server&version=1.0.11

Persilsoft.Recaptcha.Server

It exposes an endpoint to interact with the Google API to validate a reCAPTCHA V3 token.


Example:

First, you need to register the group of services required by the backend.

using Persilsoft.Recaptcha.Server.Options;
using ServiceCollectionExtensions;

Action<RecaptchaOptions> recaptchaOptionsConfigurator = options =>
builder.Configuration.GetSection(RecaptchaOptions.SectionKey).Bind(options);

builder.Services.AddRecaptchaService(recaptchaOptionsConfigurator);

In the appsetting.json configuration file, you need to configure the following key:

"Recaptcha": {
    "VerifyEndpoint": "https://www.google.com/recaptcha/api/siteverify",
    "SecretKey": "xxxxxxxx"
  }

Where:
VerifyEndpoint: It is the private key provided by Google to interact with their services.

Once the services are registered, you need to add to the AspNet Core pipeline the Endpoints that interact with the Google API:

using WebApplicationExtensions;

app.MapRecaptchaEndpoints();

Now, you can test the endpoint. If your WebApi has Swagger installed and configured, you'll be able to visualize and execute it. Sin titulo

Verify token

To validate a Recaptcha token, it needs to be validated with the Google API through this endpoint, which has the following JSON structure:

{
  "token": "string"
}

Note: To obtain a Recaptcha token, you can refer to the documentation of the package Persilsoft.Recaptcha.Blazor.

Token restrictions:

  • Each reCAPTCHA user response token is valid for two minutes, and can only be verified once to prevent replay attacks. If you need a new token, you can re-run the reCAPTCHA verification.
  • After you get the response token, you need to verify it within two minutes with reCAPTCHA using the following API to ensure the token is valid.

If an error occurs while validating the Recaptcha token, a 'VerifyRecaptchaTokenException' exception will be thrown. You can implement a custom exception handler to handle it and format the response appropriately, or you can register the exception handler included in this package.

builder.Services.AddRecaptchaExceptionHandler();

And include it in the pipeline of your AspNet Core application.

app.UseExceptionHandler(builder => { });

For more information about verifying the reCAPTCHA token, you can visit the following link:
https://developers.google.com/recaptcha/docs/verify

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 (1)

Showing the top 1 NuGet packages that depend on Persilsoft.Recaptcha.Server:

Package Downloads
Persilsoft.Membership.Backend.IoC

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.11 94 5/5/2024
1.0.10 129 5/4/2024
1.0.9 66 5/1/2024
1.0.8 70 4/28/2024
1.0.7 72 4/27/2024
1.0.5 71 4/27/2024
1.0.4 78 4/27/2024
1.0.2 84 4/21/2024
1.0.1 81 4/21/2024
1.0.0 88 4/21/2024