https://github.com/shinyscorpion/google_recaptcha
Google Recaptcha API Client for Elixir.
https://github.com/shinyscorpion/google_recaptcha
elixir elixir-lang google-recaptcha hex recaptcha
Last synced: about 1 year ago
JSON representation
Google Recaptcha API Client for Elixir.
- Host: GitHub
- URL: https://github.com/shinyscorpion/google_recaptcha
- Owner: shinyscorpion
- Created: 2017-07-07T10:20:47.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-09-26T00:05:30.000Z (over 2 years ago)
- Last Synced: 2025-04-14T18:05:43.590Z (about 1 year ago)
- Topics: elixir, elixir-lang, google-recaptcha, hex, recaptcha
- Language: Elixir
- Homepage:
- Size: 35.2 KB
- Stars: 7
- Watchers: 6
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Google Recaptcha
[](https://hex.pm/packages/google_recaptcha)
[](https://travis-ci.org/shinyscorpion/google_recaptcha)
[](http://inch-ci.org/github/shinyscorpion/google_recaptcha)
[](https://coveralls.io/github/shinyscorpion/google_recaptcha?branch=master)
Google Recaptcha API Client for Elixir.
## Installation
1. Add `google_recaptcha` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[{:google_recaptcha, "~> 0.2.0"}]
end
```
2. Run `mix deps.get` to install it.
## Configuration
API keys is needed to get the client working, you can generate [here](https://www.google.com/recaptcha/admin)
And set the keys in your project configuration file:
```elixir
config :google_recaptcha,
api_url: "https://www.google.com/recaptcha/api/siteverify",
public_key: "YOUR_PUBLIC_KEY",
secret_key: "YOUR_SECRET_KEY",
enabled: true # You may set false for development
```
## Documentation
* https://hexdocs.pm/google_recaptcha/
## Usage
Check if the captcha is valid, returns `:ok` when it is valid and `{:error, :error_type}` when something goes wrong:
```elixir
# When captcha is valid
iex> GoogleRecaptcha.verify(captcha_response, client_ip_addres)
...> :ok
iex> GoogleRecaptcha.verify(captcha_response, client_ip_addres)
...> {:error, :invalid_captcha}
```
Check if the captcha is valid(check if the recaptcha is enabled), in this case returns bolean(any error will be return as `false`):
```elixir
# When captcha is valid
iex> GoogleRecaptcha.valid?(captcha_response, client_ip_addres)
...> true
# When captcha is disabled
iex> GoogleRecaptcha.valid?(captcha_response, client_ip_addres)
...> true
# Wrong captcha response
iex> GoogleRecaptcha.valid?(wrong_captcha_response, client_ip_addres)
...> false
```