{"id":19991246,"url":"https://github.com/TimothyMeadows/reCAPTCHA.AspNetCore","last_synced_at":"2025-05-04T10:31:18.969Z","repository":{"id":33011167,"uuid":"109067687","full_name":"TimothyMeadows/reCAPTCHA.AspNetCore","owner":"TimothyMeadows","description":"Google reCAPTCHA v2/v3 for .NET Core 3.x","archived":false,"fork":false,"pushed_at":"2024-11-22T15:59:31.000Z","size":1279,"stargazers_count":144,"open_issues_count":1,"forks_count":51,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-12T10:22:29.177Z","etag":null,"topics":["asp-net-core","asp-net-mvc","aspnetcore","core2","core3","core31","dotnet","dotnet-core","google-recaptcha","netframework","nuget","recaptcha"],"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/TimothyMeadows.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-01T00:40:04.000Z","updated_at":"2024-11-22T15:36:07.000Z","dependencies_parsed_at":"2025-03-29T04:35:11.042Z","dependency_job_id":null,"html_url":"https://github.com/TimothyMeadows/reCAPTCHA.AspNetCore","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimothyMeadows%2FreCAPTCHA.AspNetCore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimothyMeadows%2FreCAPTCHA.AspNetCore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimothyMeadows%2FreCAPTCHA.AspNetCore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimothyMeadows%2FreCAPTCHA.AspNetCore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TimothyMeadows","download_url":"https://codeload.github.com/TimothyMeadows/reCAPTCHA.AspNetCore/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252320186,"owners_count":21729086,"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":["asp-net-core","asp-net-mvc","aspnetcore","core2","core3","core31","dotnet","dotnet-core","google-recaptcha","netframework","nuget","recaptcha"],"created_at":"2024-11-13T04:51:40.873Z","updated_at":"2025-05-04T10:31:15.499Z","avatar_url":"https://github.com/TimothyMeadows.png","language":"C#","funding_links":[],"categories":["C\\#"],"sub_categories":[],"readme":"# reCAPTCHA.AspNetCore\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![nuget](https://img.shields.io/nuget/v/reCAPTCHA.AspNetCore.svg)](https://www.nuget.org/packages/reCAPTCHA.AspNetCore/)\n\nGoogle reCAPTCHA for .NET Core 3.x. The older .NET Core 2.x version can be found [here](https://github.com/TimothyMeadows/reCAPTCHA.AspNetCore/tree/2.x).\n\n*Note: There have been changes to this libraries structure between versions 2, and 3. If you still wish to use version 2 it's been frozen at version 2.2.5 on nuget.*\n\n# Install\n\nFrom a command prompt\n```bash\ndotnet add package reCAPTCHA.AspNetCore\n```\n\n```bash\nInstall-Package reCAPTCHA.AspNetCore\n```\n\nYou can also search for package via your nuget ui / website:\n\nhttps://www.nuget.org/packages/reCAPTCHA.AspNetCore/\n\n# Requirements\nYou must first have a **secret key** and a **site key** in order to use the reCAPTCHA service. This package supports v2 and v3 api keys. You can read more about reCAPTCHA v2, and v3 as well as sign up for free here: https://www.google.com/recaptcha/intro/\n\n# Configure\n\nChoose how you want to configure the storage of your ```RecaptchaSettings```. This contains your site key, and site secret so it's recommended to use ```secrets.json``` with Azure Key Vault (or similar setup). However you can also just add the section to your ```appconfig.json``` file.\n\n\n#### appconfig.json\n\nAdd the follow entry to the file make sure to paste in your secret key and site key followed by setting the correct version to v2 or v3 depending on your key type:\n```json\n\"RecaptchaSettings\": {\n    \"SecretKey\": \"paste secret key here\",\n    \"SiteKey\": \"paste site key here\"\n  } \n```\n\n#### secrets.json\nRight click on your project file and goto Manage Secrets.\n\nThis will open secrets.json. Add the follow entry to the file make sure to paste in your secret key and site key followed by setting the correct version to v2 or v3 depending on your key type:\n```json\n\"RecaptchaSettings\": {\n    \"SecretKey\": \"paste secret key here\",\n    \"SiteKey\": \"paste site key here\"\n  } \n```\n\n*Note: This will also require you to have a setup such as Azure Key Vault (or similar setup) when running in production.*\n\n#### Content Security Policy\n\nIf you use a content security policy you can specify the values for script-src, and frame-src using the below example. Note that you should also make sure the Site option used for those who suffer from censorship matches the values you are using. The default value for Site is www.google.com.\n\n```json\n\"RecaptchaSettings\": {\n    \"SecretKey\": \"paste secret key here\",\n    \"SiteKey\": \"paste site key here\",\n    \"ContentSecurityPolicy\": \"https://www.google.com/recaptcha/\"\n  } \n```\n\nThis is an example for those that have to use recaptcha.net which would also have to change the site value:\n\n```json\n\"RecaptchaSettings\": {\n    \"SecretKey\": \"paste secret key here\",\n    \"SiteKey\": \"paste site key here\",\n    \"Site\": \"www.recaptcha.net\",\n    \"ContentSecurityPolicy\": \"https://www.recaptcha.net/recaptcha/\"\n  } \n```\n\n# Versions\n\nThese are the currently supported versions. Below is also the list of class names for T when using ```Html.Recaptcha\u003cT\u003e```\n\n- [RecaptchaV2Checkbox](https://developers.google.com/recaptcha/docs/display)\n- [RecaptchaV2Invisible](https://developers.google.com/recaptcha/docs/invisible)\n- [RecaptchaV3HiddenInput](https://developers.google.com/recaptcha/docs/v3)\n\n# Examples\n\nOpen `Startup.cs` and add the following code as shown below to your `ConfigureServices` method:\n\n```csharp\n// Add recaptcha and pass recaptcha configuration section\nservices.AddRecaptcha(Configuration.GetSection(\"RecaptchaSettings\"));\n\n// Or configure recaptcha via options\nservices.AddRecaptcha(options =\u003e\n{\n    options.SecretKey = \"Your secret key\";\n    options.SiteKey = \"Your site key\";\n});\n```\n\n# Usage\n\nIn order to prevent having to copy and paste your site key all over your view files (a nightmare to update later). You can inject your settings from the Startup method by adding the following code to top of your view file:\n\n```csharp\n@inject IOptions\u003cRecaptchaSettings\u003e RecaptchaSettings\n```\n\nYou can then freely include the Recaptcha script inside of forms you wish to validate later in your controller (supports multiple forms).\n```csharp\n@using (Html.BeginForm(\"SomeMethod\", \"SomeController\")) {\n  @(Html.Recaptcha\u003cRecaptchaV2Checkbox\u003e(RecaptchaSettings?.Value))\n}\n```\n\nIf you wish to trigger a JavaScript function on callback you can pass a method name to the Html helper.\n```csharp\n@using (Html.BeginForm(\"SomeMethod\", \"SomeController\")) {\n  @(Html.Recaptcha\u003cRecaptchaV2Checkbox\u003e(RecaptchaSettings?.Value, new RecaptchaV2Checkbox { successCallback = \"methodName\" }))\n}\n```\n```html\n\u003cscript\u003e\n  function methodName() {\n    alert('caw caw caw!');\n  }\n\u003c/script\u003e\n```\n\nYou can specify the language in the optional model.\n\n```csharp\n@(Html.Recaptcha(RecaptchaSettings?.Value, new RecaptchaV2Checkbox\n{\n    Language = System.Globalization.CultureInfo.CurrentCulture.Name.Substring(0,2)\n}))\n```\n\nYou may find that you need to add a reference to Microsoft.Extensions.Options before you can use IOptions.\n\n```csharp\n@using Microsoft.Extensions.Options\n@using reCAPTCHA.AspNetCore\n```\n\nYou can see a tested example of usage in the [Contact.cshtml](https://github.com/TimothyMeadows/reCAPTCHA.AspNetCore/blob/master/reCAPTCHA.AspNetCore.Example/Views/Home/Contact.cshtml) view. However you will need to configure it with your key information before running yourself. You should also take note of the allowed domains security policy in the Google Recaptcha docs.\n\n# Validation\n\nYou can validate the recaptcha attempts using the ValidateRecaptchaAttribute on your HttpPost method:\n\n```csharp\n[HttpPost]\n[ValidateRecaptcha]\npublic async Task\u003cIActionResult\u003e SomeMethod(SomeModel model)\n{\n  return View(model);\n}\n```\n\nYou can also specify a minimum score you wish to accept when a success occurs:\n\n```csharp\n[HttpPost]\n[ValidateRecaptcha(0.5)]\npublic async Task\u003cIActionResult\u003e SomeMethod(SomeModel model)\n{\n  return View(model);\n}\n```\n\nYou can see a tested example of usage in the [HomeController.cs](https://github.com/TimothyMeadows/reCAPTCHA.AspNetCore/blob/master/reCAPTCHA.AspNetCore.Example/Controllers/HomeController.cs) controller. However you will need to configure it with your key information before running yourself. You should also take note of the allowed domains security policy in the Google Recaptcha docs.\n\n# Recaptcha.net\n\nUsers who suffer from censorship concerns can now bypass the libraries default of www.google.com to www.recaptcha.net, or a proxy of there choosing using the following optional setting in ```appsettings.json```.\n\n```csharp\n\"RecaptchaSettings\": {\n    \"Site\": \"www.recaptcha.net\",\n    \"SecretKey\": \"paste secret key here\",\n    \"SiteKey\": \"paste site key here\"\n  }\n```\n\n# Unique Issues / Solutions\n\n- [Testing / Localhost Development](https://github.com/TimothyMeadows/reCAPTCHA.AspNetCore/issues/82)\n- [IsAsync empty response](https://github.com/TimothyMeadows/reCAPTCHA.AspNetCore/issues/81)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTimothyMeadows%2FreCAPTCHA.AspNetCore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FTimothyMeadows%2FreCAPTCHA.AspNetCore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTimothyMeadows%2FreCAPTCHA.AspNetCore/lists"}