{"id":23337328,"url":"https://github.com/griesoft/aspnetcore-recaptcha","last_synced_at":"2025-04-09T21:17:58.000Z","repository":{"id":40560244,"uuid":"240614140","full_name":"griesoft/aspnetcore-recaptcha","owner":"griesoft","description":"A Google reCAPTCHA service for ASP.NET Core. Keep bots away from submitting forms or other actions in just a few steps.","archived":false,"fork":false,"pushed_at":"2024-01-23T13:00:57.000Z","size":876,"stargazers_count":16,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T21:17:48.464Z","etag":null,"topics":["aspnetcore","aspnetcore-mvc","recaptcha","recaptcha-v2","recaptcha-v3","recaptcha-validation"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/griesoft.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-14T23:09:40.000Z","updated_at":"2025-04-09T10:15:26.000Z","dependencies_parsed_at":"2022-08-09T23:10:33.831Z","dependency_job_id":null,"html_url":"https://github.com/griesoft/aspnetcore-recaptcha","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/griesoft%2Faspnetcore-recaptcha","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/griesoft%2Faspnetcore-recaptcha/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/griesoft%2Faspnetcore-recaptcha/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/griesoft%2Faspnetcore-recaptcha/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/griesoft","download_url":"https://codeload.github.com/griesoft/aspnetcore-recaptcha/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248111973,"owners_count":21049578,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aspnetcore","aspnetcore-mvc","recaptcha","recaptcha-v2","recaptcha-v3","recaptcha-validation"],"created_at":"2024-12-21T02:16:42.493Z","updated_at":"2025-04-09T21:17:57.972Z","avatar_url":"https://github.com/griesoft.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ASP.NET Core reCAPTCHA\nA Google reCAPTCHA service for ASP.NET Core. Keep bots away from submitting forms or other actions in just a few steps.\n\nThe service supports V2 and V3 and comes with tag helpers that make it easy to add challenges to your forms. Also, backend validation is made easy and requires only the use of an attribute in your controllers or actions that should get validated.\n\n[![Build Status](https://dev.azure.com/griesingersoftware/ASP.NET%20Core%20Recaptcha/_apis/build/status/jgdevlabs.aspnetcore-recaptcha?branchName=master)](https://dev.azure.com/griesingersoftware/ASP.NET%20Core%20Recaptcha/_build/latest?definitionId=17\u0026branchName=master)\n[![Build Status](https://vsrm.dev.azure.com/griesingersoftware/_apis/public/Release/badge/f9036ec9-eb1c-4aff-a2b8-27fdaa573d0f/1/2)](https://vsrm.dev.azure.com/griesingersoftware/_apis/public/Release/badge/f9036ec9-eb1c-4aff-a2b8-27fdaa573d0f/1/2)\n[![License](https://badgen.net/github/license/griesoft/aspnetcore-recaptcha)](https://github.com/griesoft/aspnetcore-recaptcha/blob/master/LICENSE)\n[![NuGet](https://badgen.net/nuget/v/Griesoft.AspNetCore.ReCaptcha)](https://www.nuget.org/packages/Griesoft.AspNetCore.ReCaptcha)\n[![GitHub Release](https://badgen.net/github/release/griesoft/aspnetcore-recaptcha)](https://github.com/griesoft/aspnetcore-recaptcha/releases)\n\n## Installation\n\nInstall via [NuGet](https://www.nuget.org/packages/Griesoft.AspNetCore.ReCaptcha/) using:\n\n`PM\u003e Install-Package Griesoft.AspNetCore.ReCaptcha`\n\n## Quickstart\n\n### Prequisites\nYou will need an API key pair which can be acquired by [signing up here](http://www.google.com/recaptcha/admin). For assistance or other questions regarding that topic, refer to [Google's guide](https://developers.google.com/recaptcha/intro#overview).\n\nAfter sign-up, you should have a **Site key** and a **Secret key**. You will need those to configure the service in your app.\n\n### Configuration\n\n#### Settings\n\nOpen your `appsettings.json` and add the following lines:\n\n```json\n\"RecaptchaSettings\": {\n    \"SiteKey\": \"\u003cYour site key goes here\u003e\",\n    \"SecretKey\": \"\u003cYour secret key goes here\u003e\"\n}\n```\n**Important:** The `SiteKey` will be exposed to the public, so make sure you don't accidentally swap it with the `SecretKey`.\n\n#### Service Registration\n\nRegister this service by calling the `AddRecaptchaService()` method which is an extension method of `IServiceCollection`. For example:\n\n##### .NET 6\n\n```csharp\nvar builder = WebApplication.CreateBuilder(args);\n\nbuilder.Services.AddRecaptchaService();\n```\n\n##### Prior to .NET 6\n\n```csharp\npublic void ConfigureServices(IServiceCollection services)\n{\n    services.AddRecaptchaService();\n}\n```\n\n### Adding a reCAPTCHA element to your view\n\nFirst, import the tag helpers. Open your `_ViewImports.cshtml` file and add the following lines:\n\n```razor\n@using Griesoft.AspNetCore.ReCaptcha\n@addTagHelper *, Griesoft.AspNetCore.ReCaptcha\n```\n\nNext, you need to add the `\u003crecaptcha-script\u003e` to every view you intend to use the reCAPTCHA. That will render the API script. Preferably you would add this somewhere close to the bottom of your body element.\n\nNow you may add a reCAPTCHA challenge to your view where ever you need it. Using the `\u003crecaptcha /\u003e` tag in your form will render a reCAPTCHA V2 checkbox inside it.\n\nFor invisible reCAPTCHA use:\n```html\n\u003cbutton re-invisible form-id=\"yourFormId\"\u003eSubmit\u003c/button\u003e\n```\n\nFor reCAPTCHA V3 use:\n```html\n\u003crecaptcha-v3 form-id=\"yourFormId\" action=\"submit\"\u003eSubmit\u003c/recaptcha-v3\u003e\n```\n\n### Adding backend validation to an action\n\nValidation is done by decorating your controller or action with `[ValidateRecaptcha]`.\n\nFor example:\n\n```csharp\nusing Griesoft.AspNetCore.ReCaptcha;\nusing Microsoft.AspNetCore.Mvc;\n\nnamespace ReCaptcha.Sample.Controllers\n{\n    public class ExampleController : Controller\n    {\n        [ValidateRecaptcha]\n        public IActionResult FormSubmit(SomeModel model)\n        {\n            // Will hit the next line only if validation was successful\n            return View(\"FormSubmitSuccessView\");\n        }\n    }\n}\n```\nNow each incoming request to that action will be validated for a valid reCAPTCHA token.\n\nThe default behavior for invalid tokens is a 404 (BadRequest) response. But this behavior is configurable, and you may also instead request the validation result as an argument to your action. \n\nThis can be achieved like this:\n\n```csharp\n[ValidateRecaptcha(ValidationFailedAction = ValidationFailedAction.ContinueRequest)]\npublic IActionResult FormSubmit(SomeModel model, ValidationResponse recaptchaResponse)\n{\n    if (!recaptchaResponse.Success)\n    {\n        return BadRequest();\n    }\n\n    return View(\"FormSubmitSuccessView\");\n}\n```\n\nIn case you are validating a reCAPTCHA V3 token, make sure you also add an action name to your validator.  \n\nFor example:\n\n```csharp\n[ValidateRecaptcha(Action = \"submit\")]\npublic IActionResult FormSubmit(SomeModel model)\n{\n    return View(\"FormSubmitSuccessView\");\n}\n```\n\n## Options \u0026 Customization\n\nThere are global defaults that you may modify on your application startup. Also, the appearance and position of V2 tags may be modified. Either globally or each tag individually.\n\nAll options from the [official reCAPTCHA docs](https://developers.google.com/recaptcha/intro) are available to you in this package.\n\n## Proxy Server\n\nIf your environment requires to use forward proxy server, this can be done by specifying two additional parameters in the configuration file\n\n```json\n\"RecaptchaSettings\": {\n    \"UseProxy\": true,\n    \"ProxyAddress\": \"http://10.1.2.3:80\"\n}\n```\n\nThe address should contain port and protocol, as required by the System.Net.WebProxy class.\n## Detailed Documentation\nIs on it's way...\n\n## Contributing\nContributing is heavily encouraged. :muscle: The best way of doing so is by first starting a discussion about new features or improvements you would like to make. Or, in case of a bug, report it first by creating a new issue. From there, you may volunteer to fix it if you like. 😄\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgriesoft%2Faspnetcore-recaptcha","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgriesoft%2Faspnetcore-recaptcha","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgriesoft%2Faspnetcore-recaptcha/lists"}