BlazorReCaptcha 1.0.1
dotnet add package BlazorReCaptcha --version 1.0.1
NuGet\Install-Package BlazorReCaptcha -Version 1.0.1
<PackageReference Include="BlazorReCaptcha" Version="1.0.1" />
paket add BlazorReCaptcha --version 1.0.1
#r "nuget: BlazorReCaptcha, 1.0.1"
// Install BlazorReCaptcha as a Cake Addin
#addin nuget:?package=BlazorReCaptcha&version=1.0.1
// Install BlazorReCaptcha as a Cake Tool
#tool nuget:?package=BlazorReCaptcha&version=1.0.1
BlazorReCaptcha Component
BlazorReCaptcha is a Blazor component that simplifies the integration of Google's reCAPTCHA v2 into your Blazor applications. This component allows you to easily add reCAPTCHA capabilities to your forms and handle client-side and server-side validation.
Prerequisites
Before using this component, ensure that you have the following:
- Google reCAPTCHA API Keys: You need a Site Key and a Secret Key from the reCAPTCHA website for the component to work correctly.
Installation
To use BlazorReCaptcha in your Blazor application, you can install the NuGet package:
dotnet add package BlazorReCaptcha
Usage
- Add the script reference to your
app.razor
<script src="_content/BlazorReCaptcha/BlazorReCaptcha.js"></script>
- Add the component to your Razor page or component
<ReCaptcha @ref="reCaptcha" SiteKey="your_site_key" Secret="your_secret_key" OnClientSuccess="OnClientSuccess" OnExpired="OnExpired" />
or
<ReCaptcha @ref="reCaptcha" OnClientSuccess="OnClientSuccess" OnExpired="OnExpired" />
- Handle success and expiration events
@code {
async Task HandleClientSuccess()
{
// Handle client-side success
}
async Task HandleExpired()
{
// Handle expiration
}
}
- Accessing reCAPTCHA response in code
var response = await captcha.GetResponseAsync();
- Verify the reCAPTCHA response on the server
var verificationResult = await captcha.Verify(response);
Parameters
SiteKey
: Your reCAPTCHA Site Key.Secret
: Your reCAPTCHA Secret Key.OnClientSuccess
: Event callback
async Task HandleClientSuccess(string response)
{
// Handle client-side success
}
OnExpired
: Event callback
async Task HandleExpired()
{
// Handle expiration
}
Examples
For a complete example of how to use this component, check the BlazorReCaptchaSample in this repository.
Configuration
You can configure the reCAPTCHA keys in your appsettings.json
file:
{
"ReCaptcha": {
"Sitekey": "your_site_key",
"Secret": "your_secret_key"
}
}
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- This component is inspired by the Google reCAPTCHA documentation.
- Special thanks to the Blazor community for their contributions and feedback.
Feel free to contribute, open issues, or provide feedback to make this component even better!
Product | Versions 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. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.