{"id":13508158,"url":"https://github.com/samueljseay/recaptcha","last_synced_at":"2025-04-04T12:09:54.140Z","repository":{"id":46008130,"uuid":"41432019","full_name":"samueljseay/recaptcha","owner":"samueljseay","description":"A simple reCaptcha 2 library for Elixir applications.","archived":false,"fork":false,"pushed_at":"2023-02-02T03:51:25.000Z","size":65,"stargazers_count":113,"open_issues_count":12,"forks_count":58,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-04T02:47:33.278Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Elixir","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/samueljseay.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-26T14:59:02.000Z","updated_at":"2025-01-09T18:03:20.000Z","dependencies_parsed_at":"2023-02-17T14:00:29.428Z","dependency_job_id":null,"html_url":"https://github.com/samueljseay/recaptcha","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samueljseay%2Frecaptcha","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samueljseay%2Frecaptcha/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samueljseay%2Frecaptcha/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samueljseay%2Frecaptcha/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samueljseay","download_url":"https://codeload.github.com/samueljseay/recaptcha/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247174454,"owners_count":20896078,"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":[],"created_at":"2024-08-01T02:00:49.039Z","updated_at":"2025-04-04T12:09:54.109Z","avatar_url":"https://github.com/samueljseay.png","language":"Elixir","funding_links":[],"categories":["Framework Components"],"sub_categories":[],"readme":"# Recaptcha\n\n[![Build Status](https://travis-ci.org/samueljseay/recaptcha.svg?branch=master)](https://travis-ci.org/samueljseay/recaptcha)\n[![Coverage Status](https://coveralls.io/repos/github/samueljseay/recaptcha/badge.svg?branch=master)](https://coveralls.io/github/samueljseay/recaptcha)\n[![Module Version](https://img.shields.io/hexpm/v/recaptcha.svg)](https://hex.pm/packages/recaptcha)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/recaptcha/)\n[![Total Download](https://img.shields.io/hexpm/dt/recaptcha.svg)](https://hex.pm/packages/recaptcha)\n[![License](https://img.shields.io/hexpm/l/recaptcha.svg)](https://github.com/samueljseay/recaptcha/blob/master/LICENSE)\n[![Last Updated](https://img.shields.io/github/last-commit/samueljseay/recaptcha.svg)](https://github.com/samueljseay/recaptcha/commits/master)\n\nA simple Elixir package for implementing [reCAPTCHA] in Elixir applications.\n\n[reCAPTCHA]: http://www.google.com/recaptcha\n\n## Migration from 1.x\n\n### Breaking Changes\n\n1. Template functionality is now in a separate module: `Recaptcha.Template`. Please note: in future templating may move to a Phoenix specific package.\n2. `verify` API has changed, see the code for documentation of the new API.\n\nMost other questions about 2.x should be answered by looking over the documentation and the code. Please raise an issue\nif you have any problems with migrating.\n\n## Installation\n\nAdd `:recaptcha` to your `mix.exs` dependencies:\n\n```elixir\n  defp deps do\n    [\n      {:recaptcha, \"~\u003e 3.0\"},\n    ]\n  end\n```\n\nList `:recaptcha` as an application dependency:\n\n```elixir\n  def application do\n    [\n      extra_applications: [:recaptcha]\n    ]\n  end\n```\n\nRun `mix do deps.get, compile`\n\n## Config\n\nBy default the public and private keys are loaded via the `RECAPTCHA_PUBLIC_KEY` and `RECAPTCHA_PRIVATE_KEY` environment variables.\n\n```elixir\nconfig :recaptcha,\n  public_key: {:system, \"RECAPTCHA_PUBLIC_KEY\"},\n  secret: {:system, \"RECAPTCHA_PRIVATE_KEY\"}\n```\n\n### JSON Decoding\n\nBy default `reCaptcha` will use `Jason` to decode JSON responses, this can be changed as such:\n\n```elixir\nconfig :recaptcha, :json_library, Poison\n```\n\n## Usage\n\n### Render the Widget\n\nUse `raw` (if you're using Phoenix.HTML) and `Recaptcha.Template.display/1` methods to render the captcha widget.\n\nFor recaptcha with checkbox:\n\n```html\n\u003cform name=\"someform\" method=\"post\" action=\"/somewhere\"\u003e\n  ...\n  \u003c%= raw Recaptcha.Template.display %\u003e\n  ...\n\u003c/form\u003e\n```\n\nFor invisible recaptcha:\n\n```html\n\u003cform name=\"someform\" method=\"post\" action=\"/somewhere\"\u003e\n  ...\n  \u003c%= raw Recaptcha.Template.display(size: \"invisible\") %\u003e\n\u003c/form\u003e\n  ...\n```\n\nTo change the position of the invisible recaptcha, use an option badge. See https://developers.google.com/recaptcha/docs/invisible on the date-badge.\n\nSince recaptcha loads JavaScript code asynchronously, you cannot immediately submit the captcha form.\nIf you have logic that needs to know if the captcha code has already been loaded (for example disabling submit button until fully loaded), it is possible to pass in a JS-callback that will be called once the captcha has finished loading.\nThis can be done as follows:\n\n```html\n\u003cform name=\"someform\" method=\"post\" action=\"/somewhere\"\u003e\n  ...\n  \u003c%= raw Recaptcha.Template.display(onload: \"myOnLoadCallback\") %\u003e\n\u003c/form\u003e\n  ...\n```\n\nAnd then in your JS code:\n\n```javascript\nfunction myOnLoadCallback() {\n  // perform extra actions here\n}\n```\n\n`display` method accepts additional options as a keyword list, the options are:\n\nOption                  | Action                                                 | Default\n:---------------------- | :----------------------------------------------------- | :------------------------\n`noscript`              | Renders default noscript code provided by google       | `false`\n`public_key`            | Sets key to the `data-sitekey` reCaptcha div attribute | Public key from the config file\n`hl`                    | Sets the language of the reCaptcha                     | en\n\n### Verify API\n\nRecaptcha provides the `verify/2` method. Below is an example using a Phoenix controller action:\n\n```elixir\ndef create(conn, params) do\n  case Recaptcha.verify(params[\"g-recaptcha-response\"]) do\n    {:ok, response} -\u003e do_something\n    {:error, errors} -\u003e handle_error\n  end\nend\n```\n\n`verify` method sends a `POST` request to the reCAPTCHA API and returns 2 possible values:\n\n`{:ok, %Recaptcha.Response{challenge_ts: timestamp, hostname: host}}` -\u003e The captcha is valid, see the [documentation](https://developers.google.com/recaptcha/docs/verify#api-response) for more details.\n\n`{:error, errors}` -\u003e `errors` contains atomised versions of the errors returned by the API, See the [error documentation](https://developers.google.com/recaptcha/docs/verify#error-code-reference) for more details. Errors caused by timeouts in HTTPoison or Jason encoding are also returned as atoms. If the recaptcha request succeeds but the challenge is failed, a `:challenge_failed` error is returned.\n\n`verify` method also accepts a keyword list as the third parameter with the following options:\n\nOption                  | Action                                                 | Default\n:---------------------- | :----------------------------------------------------- | :------------------------\n`timeout`               | Time to wait before timeout                            | 5000 (ms)\n`secret`                | Private key to send as a parameter of the API request  | Private key from the config file\n`remote_ip`             | Optional. The user's IP address, used by reCaptcha     | no default\n\n\n## Testing\n\nIn order to test your endpoints you should set the secret key to the following value in order to receive a positive result from all queries to the Recaptcha engine.\n\n```elixir\nconfig :recaptcha,\n  secret: \"6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe\"\n```\n\nSetting up tests without network access can be done also. When configured as such a positive or negative result can be generated locally.\n\n```elixir\nconfig :recaptcha,\n  http_client: Recaptcha.Http.MockClient,\n  secret: \"6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe\"\n\n\n  {:ok, _details} = Recaptcha.verify(\"valid_response\")\n\n  {:error, _details} = Recaptcha.verify(\"invalid_response\")\n\n```\n\n## Contributing\n\nCheck out [CONTRIBUTING.md](/CONTRIBUTING.md) if you want to help.\n\n## Copyright and License\n\nCopyright (c) 2016 Samuel Seay\n\nThis library is released under the MIT License. See the [LICENSE.md](./LICENSE.md) file\nfor further details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamueljseay%2Frecaptcha","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamueljseay%2Frecaptcha","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamueljseay%2Frecaptcha/lists"}