Persilsoft.Recaptcha.Blazor 1.0.16

There is a newer version of this package available.
See the version list below for details.
dotnet add package Persilsoft.Recaptcha.Blazor --version 1.0.16                
NuGet\Install-Package Persilsoft.Recaptcha.Blazor -Version 1.0.16                
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.Blazor" Version="1.0.16" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Persilsoft.Recaptcha.Blazor --version 1.0.16                
#r "nuget: Persilsoft.Recaptcha.Blazor, 1.0.16"                
#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.Blazor as a Cake Addin
#addin nuget:?package=Persilsoft.Recaptcha.Blazor&version=1.0.16

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

Persilsoft.Recaptcha.Blazor

It exposes a service that allows you to obtain a reCAPTCHA token and validate that token through a verification endpoint that you need to add to your backend.


Example

First, you need to register the following service group in the dependency container.

using Persilsoft.Recaptcha.Blazor.Options;
using ServiceCollectionExtensions;

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

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

"Recaptcha": {
        "WebApiBaseAddress": "https://persilsoft.api",
        "VerifyRecaptcha": "/recaptcha/verify",
        "SiteKey": "xxxxxxxxxxx"
    }

Where:
WebApiBaseAddress: It is the Base URL of your backend server that will expose the token verification endpoint.
VerifyRecaptcha: It is the token verification endpoint on your backend server.
SiteKey: It is your website key, also known as the reCAPTCHA key.

Now, you can use the service in your Razor page.

@page "/recaptcha"
@using Persilsoft.Recaptcha.Shared.Interfaces
@inject IRecaptchaValidatorService RecaptchaValidatorService

<h3>Demo</h3>

<EditForm Model="@model" OnValidSubmit="Send">
    <DataAnnotationsValidator />
    <div class="mb-3">
        <label for="name" class="form-label">Nombre</label>
        <input type="text" @bind="model.Name" class="form-control" id="name" name="name" />
        <ValidationMessage For="@(() => model.Name)" />
    </div>
    <div class="d-grid gap-2 col-6 mx-auto">
        <button class="btn btn-danger" type="submit">Enviar</button>
    </div>
    <hr />
    <div class="mt-3">
        <textarea disabled class="form-control">
            @result
        </textarea>
    </div>
</EditForm>

@code {
    private readonly PersonModel model = new();
    private string result;

    private async Task Send()
    {
        try
        {
            await RecaptchaValidatorService.TryVerifyInteraction();
            result = "Successful validation!!!";
        }
        catch (Exception ex)
        {
            result = ex.Message;
        }
    }

    public class PersonModel
    {
        [Required(ErrorMessage = "{0} is required.")]
        public string Name { get; set; }
    }
}

Note: The invocation of the TryVerifyInteraction method will throw an exception if the reCAPTCHA validation process fails.

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.Blazor:

Package Downloads
Persilsoft.Membership.Blazor

Contains razor clases for use in frontend membership projects

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.31 63 10/16/2024
1.0.30 64 10/16/2024
1.0.29 40 10/15/2024
1.0.28 93 10/14/2024
1.0.27 93 10/6/2024
1.0.26 84 10/4/2024
1.0.25 89 10/4/2024
1.0.24 104 9/1/2024
1.0.23 126 8/28/2024
1.0.22 82 8/28/2024
1.0.21 110 8/18/2024
1.0.20 101 8/18/2024
1.0.19 109 8/17/2024
1.0.18 100 8/17/2024
1.0.17 111 8/17/2024
1.0.16 73 7/29/2024
1.0.15 240 7/20/2024
1.0.14 272 5/26/2024
1.0.13 91 5/26/2024
1.0.12 211 5/25/2024
1.0.11 108 5/25/2024
1.0.10 114 5/25/2024
1.0.9 142 5/23/2024
1.0.8 258 5/18/2024
1.0.7 117 5/18/2024
1.0.6 150 5/17/2024
1.0.5 130 5/5/2024
1.0.4 117 5/4/2024
1.0.3 69 5/3/2024
1.0.2 77 5/1/2024
1.0.1 101 4/24/2024
1.0.0 103 4/22/2024