{"id":13711975,"url":"https://github.com/middlewares/recaptcha","last_synced_at":"2025-05-06T21:32:48.624Z","repository":{"id":62528363,"uuid":"70466346","full_name":"middlewares/recaptcha","owner":"middlewares","description":"PSR-15 middleware to use Google reCAPTCHA for spam prevention","archived":false,"fork":false,"pushed_at":"2025-03-26T14:44:07.000Z","size":35,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-25T01:53:40.010Z","etag":null,"topics":["http","middleware","prevention","psr-15","recaptcha","security"],"latest_commit_sha":null,"homepage":null,"language":"PHP","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/middlewares.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-10T08:13:52.000Z","updated_at":"2025-03-23T10:19:26.000Z","dependencies_parsed_at":"2022-11-02T14:16:57.072Z","dependency_job_id":null,"html_url":"https://github.com/middlewares/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/middlewares%2Frecaptcha","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/middlewares%2Frecaptcha/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/middlewares%2Frecaptcha/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/middlewares%2Frecaptcha/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/middlewares","download_url":"https://codeload.github.com/middlewares/recaptcha/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252772238,"owners_count":21801884,"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":["http","middleware","prevention","psr-15","recaptcha","security"],"created_at":"2024-08-02T23:01:13.574Z","updated_at":"2025-05-06T21:32:48.320Z","avatar_url":"https://github.com/middlewares.png","language":"PHP","funding_links":[],"categories":["Packages"],"sub_categories":["Security"],"readme":"# middlewares/recaptcha\n\n[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Software License][ico-license]](LICENSE)\n![Testing][ico-ga]\n[![Total Downloads][ico-downloads]][link-downloads]\n\nMiddleware to use [google/recaptcha](https://github.com/google/recaptcha) library for spam prevention. Returns a `403` response if the request is not valid. More info about [Google reCAPTCHA](https://www.google.com/recaptcha).\n\n## Requirements\n\n* PHP \u003e= 7.2\n* A [PSR-7 http library](https://github.com/middlewares/awesome-psr15-middlewares#psr-7-implementations)\n* A [PSR-15 middleware dispatcher](https://github.com/middlewares/awesome-psr15-middlewares#dispatcher)\n\n## Installation\n\nThis package is installable and autoloadable via Composer as [middlewares/recaptcha](https://packagist.org/packages/middlewares/recaptcha).\n\n```sh\ncomposer require middlewares/recaptcha\n```\n\n## Example\n\n```php\n$dispatcher = new Dispatcher([\n    new Middlewares\\Recaptcha($secretKey),\n\n    //in your view\n    function () {\n        echo '\u003cdiv class=\"g-recaptcha\" data-sitekey=\"XXX\"\u003e\u003c/div\u003e';\n        echo '\u003cscript type=\"text/javascript\" src=\"https://www.google.com/recaptcha/api.js\"\u003e\u003c/script\u003e';\n    }\n]);\n\n$response = $dispatcher-\u003edispatch(new ServerRequest());\n```\n\n## Usage\n\nYou need a secret API key for your app. You can register it at https://www.google.com/recaptcha/admin\n\n```php\n$secretKey = 'Your-Secret-Key';\n\n$recaptcha = new Middlewares\\Recaptcha($secretKey);\n```\n\nOptionally, you can provide a `Psr\\Http\\Message\\ResponseFactoryInterface` as the second argument to create the error responses (`403`). If it's not defined, [Middleware\\Utils\\Factory](https://github.com/middlewares/utils#factory) will be used to detect it automatically.\n\n```php\n$responseFactory = new MyOwnResponseFactory();\n\n$recaptcha = new Middlewares\\Recaptcha($secretKey, $responseFactory);\n```\n\n### ipAttribute\n\nBy default uses the `REMOTE_ADDR` server parameter to get the client ip. This option allows to use a request attribute. Useful to combine with a ip detection middleware, for example [client-ip](https://github.com/middlewares/client-ip):\n\n```php\n$dispatcher = new Dispatcher([\n    //detect the client ip and save it in \"ip\" attribute\n    (new Middlewares\\ClientIP())-\u003eattribute('ip'),\n\n    //use that attribute\n    (new Middlewares\\Recaptcha($secretKey))-\u003eipAttribute('ip')\n]);\n```\n\n---\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information about recent changes and [CONTRIBUTING](CONTRIBUTING.md) for contributing details.\n\nThe MIT License (MIT). Please see [LICENSE](LICENSE) for more information.\n\n[ico-version]: https://img.shields.io/packagist/v/middlewares/recaptcha.svg?style=flat-square\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\n[ico-ga]: https://github.com/middlewares/recaptcha/workflows/testing/badge.svg\n[ico-downloads]: https://img.shields.io/packagist/dt/middlewares/recaptcha.svg?style=flat-square\n\n[link-packagist]: https://packagist.org/packages/middlewares/recaptcha\n[link-downloads]: https://packagist.org/packages/middlewares/recaptcha\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiddlewares%2Frecaptcha","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmiddlewares%2Frecaptcha","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiddlewares%2Frecaptcha/lists"}