AspNetCore.WebApi.GoogleReCaptcha
0.4.1
.NET 5.0
This package targets .NET 5.0. The package is compatible with this framework or higher.
.NET Core 2.1
This package targets .NET Core 2.1. The package is compatible with this framework or higher.
dotnet add package AspNetCore.WebApi.GoogleReCaptcha --version 0.4.1
NuGet\Install-Package AspNetCore.WebApi.GoogleReCaptcha -Version 0.4.1
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="AspNetCore.WebApi.GoogleReCaptcha" Version="0.4.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AspNetCore.WebApi.GoogleReCaptcha --version 0.4.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: AspNetCore.WebApi.GoogleReCaptcha, 0.4.1"
#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 AspNetCore.WebApi.GoogleReCaptcha as a Cake Addin #addin nuget:?package=AspNetCore.WebApi.GoogleReCaptcha&version=0.4.1 // Install AspNetCore.WebApi.GoogleReCaptcha as a Cake Tool #tool nuget:?package=AspNetCore.WebApi.GoogleReCaptcha&version=0.4.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Google ReCaptcha Extension for AspNetCore Web API
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddReCaptcha(opt =>
{
opt.Secret = "your_secret";
opt.Defaults.Input = InputType.Body;
opt.Defaults.InputName = "g-captcha-response";
});
}
OR
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddReCaptcha();
}
appsettings.json
"ReCaptcha":{
"Secret":"your_secret"
}
For use recaptcha validation, add [ReCaptcha]
attribute
public class HomeController: ControllerBase
{
[HttpPost]
[ReCaptcha]
public async Task<IActionResult> ForgotPassword()
{
return Ok();
}
}
Example request
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<script src="https://code.jquery.com/jquery-3.4.1.min.js" ></script>
<script type="text/javascript">
$(function(){
$('button').click(function(){
$.ajax({
url:"your_api_endpoint",
type: 'post',
headers: {
"encodedResponse": grecaptcha.getResponse()
}
});
});
});
</script>
</head>
<body>
<form action="#" method="POST">
<div class="g-recaptcha" data-sitekey="your_public_key"></div>
<button type="button">POST</button>
</form>
</body>
</html>
For Debug or Test mode
public void ConfigureServices(IServiceCollection services)
{
services.AddReCaptcha();
GoogleReCaptcha.ResponseCodeForTest = "abc123";
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://code.jquery.com/jquery-3.4.1.min.js" ></script>
<script type="text/javascript">
$(function(){
$('button').click(function(){
$.ajax({
url:"your_api_endpoint",
type: 'post',
headers: {
"encodedResponse": "abc123"
}
});
});
});
</script>
</head>
<body>
<form action="#" method="POST">
<div class="g-recaptcha" data-sitekey="your_public_key"></div>
<button type="button">POST</button>
</form>
</body>
</html>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp2.1 is compatible. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 is compatible. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETCoreApp 2.1
- Microsoft.AspNetCore.Mvc.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.5)
- Microsoft.Extensions.DependencyInjection (>= 3.1.1)
- Microsoft.Extensions.Http (>= 3.1.1)
- Newtonsoft.Json (>= 12.0.3)
- System.Net.Http (>= 4.3.4)
-
.NETCoreApp 3.1
- Microsoft.AspNetCore.Mvc.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.5)
- Microsoft.Extensions.DependencyInjection (>= 3.1.1)
- Microsoft.Extensions.Http (>= 3.1.1)
- System.Net.Http (>= 4.3.4)
-
net5.0
- Microsoft.AspNetCore.Mvc.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.5)
- Microsoft.Extensions.DependencyInjection (>= 5.0.2)
- Microsoft.Extensions.Http (>= 5.0.0)
- System.Net.Http (>= 4.3.4)
-
net6.0
- Microsoft.AspNetCore.Mvc.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.5)
- Microsoft.Extensions.DependencyInjection (>= 6.0.0)
- Microsoft.Extensions.Http (>= 6.0.0)
- System.Net.Http (>= 4.3.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.