AspNetCore.WebApi.GoogleReCaptcha 0.3.7

There is a newer version of this package available.
See the version list below for details.
dotnet add package AspNetCore.WebApi.GoogleReCaptcha --version 0.3.7                
NuGet\Install-Package AspNetCore.WebApi.GoogleReCaptcha -Version 0.3.7                
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.3.7" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AspNetCore.WebApi.GoogleReCaptcha --version 0.3.7                
#r "nuget: AspNetCore.WebApi.GoogleReCaptcha, 0.3.7"                
#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.3.7

// Install AspNetCore.WebApi.GoogleReCaptcha as a Cake Tool
#tool nuget:?package=AspNetCore.WebApi.GoogleReCaptcha&version=0.3.7                

Google ReCaptcha Extension for AspNetCore Web API

Nuget

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

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
0.4.1 379 1/16/2023
0.3.9 506 5/31/2022
0.3.8 554 5/17/2022
0.3.7 496 5/9/2022
0.3.6 479 5/9/2022