Persilsoft.Recaptcha.Blazor 1.0.25

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.25                
NuGet\Install-Package Persilsoft.Recaptcha.Blazor -Version 1.0.25                
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.25" />                
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.25                
#r "nuget: Persilsoft.Recaptcha.Blazor, 1.0.25"                
#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.25

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

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:

"RecaptchaOptions": {
        "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 IRecaptchaService RecaptchaService

<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 RecaptchaService.TryVerifyInteractionAsync();
            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 TryVerifyInteractionAsync 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 127 10/16/2024
1.0.30 98 10/16/2024
1.0.29 55 10/15/2024
1.0.28 99 10/14/2024
1.0.27 100 10/6/2024
1.0.26 91 10/4/2024
1.0.25 98 10/4/2024
1.0.24 111 9/1/2024
1.0.23 128 8/28/2024
1.0.22 84 8/28/2024
1.0.21 112 8/18/2024
1.0.20 103 8/18/2024
1.0.19 112 8/17/2024
1.0.18 102 8/17/2024
1.0.17 114 8/17/2024
1.0.16 74 7/29/2024
1.0.15 243 7/20/2024
1.0.14 273 5/26/2024
1.0.13 92 5/26/2024
1.0.12 212 5/25/2024
1.0.11 109 5/25/2024
1.0.10 115 5/25/2024
1.0.9 143 5/23/2024
1.0.8 259 5/18/2024
1.0.7 118 5/18/2024
1.0.6 151 5/17/2024
1.0.5 131 5/5/2024
1.0.4 118 5/4/2024
1.0.3 70 5/3/2024
1.0.2 78 5/1/2024
1.0.1 102 4/24/2024
1.0.0 105 4/22/2024