KITT.Web.ReCaptcha.Blazor 1.0.2

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

// Install KITT.Web.ReCaptcha.Blazor as a Cake Tool
#tool nuget:?package=KITT.Web.ReCaptcha.Blazor&version=1.0.2                

KITT.Web.ReCaptcha.Blazor

This project add Google reCaptcha to your Blazor apps.<br/> This project targets .NET 8 as supported Framework version.

Installation

This project is available on NuGet.

It can be installed using the dotnet add package command or the NuGet wizard on your favourite IDE.

  dotnet add package KITT.Web.ReCaptcha.Blazor

reCaptcha v2

Usage

The project gives you a Razor component which add the reCaptcha v2 widget.

Add the namespace KITT.Web.ReCaptcha.Blazor.v2 to your Razor Components or in the _Imports.razor file.

After that you can use the <ReCaptcha /> component in your EditForm like in this sample:

  <ReCaptcha SiteKey="<your reCaptcha v2 client key>"
             @bind-Value="yourPropertyToBind"
             Theme="Theme.Dark"
             Size="Size.Normal"
             TabIndex="1" />

  @code {
    private string yourPropertyToBind = string.Empty;
  }

Parameters

The component needs to be used inside an EditForm. It exposes the following properties:

Property Description
SiteKey (Required) string: the value of the v2 client site key
@bind-Value string: the property to bind
Theme Theme enum: the theme to use (default: Theme.Light)
Size Size enum: the size of the widget (default: Size.Normal)
TabIndex int: the tabIndex value (default: 0)
Id string: the id of the HTML element used to render the reCaptcha widget (default: "recaptcha")

reCaptcha v3

Usage

You can register reCaptcha using the AddReCaptchaV3 extension method:

  using KITT.Web.ReCaptcha.Blazor.v3;
  //...
  builder.Services.AddReCaptchaV3(options => options.SiteKey = "<YOUR CLIENT SITE KEY VALUE>");

After that you have to add the ReCaptchaScript component.

Blazor Web App

With the new Blazor Web App you can add the ReCaptchaScript component to your App.razor:

  ....
  <ReCaptchaScript />
  <script src="_framework/blazor.web.js"></script>
Blazor WebAssembly

If you're using Blazor WebAssembly, simply register it to the RootComponents calling the extension method:

  builder.RootComponents.RegisterReCaptchaScript();
Blazor Server

If you're using Blazor Server, edit the _Host.cshtml page in this way:

  ....
  <script src="_framework/blazor.server.js"></script>
  <component type="typeof(ReCaptchaScript)" render-mode="ServerPrerendered" />

After that you can inject the ReCaptchaService to your component and call the VerifyAsync method:

  @inject ReCaptchaService ReCaptcha
  ...
  @code {
    private async Task SubmitAsync(){
      var result = await ReCaptcha.VerifyAsync(action: "submit");
      // ....
    }
  }

Samples

In the samples folder you can find samples both for reCaptcha v2 and reCaptcha v3 using the new Blazor Web App template.

The site key used in this samples is only for testing purpose.

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

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.0.3 86 10/29/2024
1.0.2 155 5/24/2024
1.0.1 307 12/9/2023
1.0.0 141 12/5/2023
0.2.1 145 11/10/2023
0.2.0 137 11/10/2023
0.1.0 176 8/9/2023