Skip to content

Latest commit

 

History

History
67 lines (47 loc) · 2.07 KB

README.md

File metadata and controls

67 lines (47 loc) · 2.07 KB

Google Recaptcha

Hex.pm Build Status Inline docs Coverage Status

Google Recaptcha API Client for Elixir.

Installation

  1. Add google_recaptcha to your list of dependencies in mix.exs:
def deps do
  [{:google_recaptcha, "~> 0.2.0"}]
end
  1. Run mix deps.get to install it.

Configuration

API keys is needed to get the client working, you can generate here

And set the keys in your project configuration file:

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

Usage

Check if the captcha is valid, returns :ok when it is valid and {:error, :error_type} when something goes wrong:

# 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):

# 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