recaptcha alternatives and similar packages
Based on the "Framework Components" category.
Alternatively, view recaptcha alternatives based on common mentions on social networks and blogs.
-
ex_admin
ExAdmin is an auto administration package for Elixir and the Phoenix Framework -
phoenix_html
Phoenix.HTML functions for working with HTML strings and templates -
phoenix_ecto
Phoenix and Ecto integration with support for concurrent acceptance testing -
absinthe_plug
Plug support for Absinthe, the GraphQL toolkit for Elixir -
phoenix_live_reload
Provides live-reload functionality for Phoenix -
params
Easy parameters validation/casting with Ecto.Schema, akin to Rails' strong parameters. -
phoenix_pubsub_redis
The Redis PubSub adapter for the Phoenix framework -
dayron
A repository `similar` to Ecto.Repo that maps to an underlying http client, sending requests to an external rest api instead of a database -
phoenix_token_auth
Token authentication solution for Phoenix. Useful for APIs for e.g. single page apps. -
rummage_phoenix
Full Phoenix Support for Rummage. It can be used for searching, sorting and paginating collections in phoenix. -
sentinel
DEPRECATED - Phoenix Authentication library that wraps Guardian for extra functionality -
plug_rails_cookie_session_store
Rails compatible Plug session store -
phx_component_helpers
Extensible Phoenix liveview components, without boilerplate -
multiverse
Elixir package that allows to add compatibility layers via API gateways. -
filterable
Filtering from incoming params in Elixir/Ecto/Phoenix with easy to use DSL. -
access pass
provides a full user authentication experience for an API. Includes login,logout,register,forgot password, forgot username, confirmation email and all that other good stuff. Includes plug for checking for authenticated users and macro for generating the required routes. -
better_params
Cleaner request parameters in Elixir web applications ๐ -
scrivener_headers
Scrivener pagination with headers and web linking -
phoenix_pubsub_rabbitmq
RabbitMQ adapter for Phoenix's PubSub layer -
plug_checkup
PlugCheckup provides a Plug for adding simple health checks to your app -
plug_rest
REST behaviour and Plug router for hypermedia web applications in Elixir -
trailing_format_plug
An elixir plug to support legacy APIs that use a rails-like trailing format: http://api.dev/resources.json -
Votex
Implements vote / like / follow functionality for Ecto models in Elixir. Inspired from Acts as Votable gem in Ruby on Rails -
phoenix_html_simplified_helpers
Some helpers for phoenix html( truncate, time_ago_in_words, number_with_delimiter, url_for, current_page? ) -
plug_canonical_host
PlugCanonicalHost ensures that all requests are served by a single canonical host.
Elixir and Phoenix Application Security Platform
Do you think we are missing an alternative of recaptcha or a related project?
README
Recaptcha
A simple Elixir package for implementing reCAPTCHA in Elixir applications.
Migration from 1.x
Breaking Changes
- Template functionality is now in a separate module:
Recaptcha.Template
. Please note: in future templating may move to a Phoenix specific package. verify
API has changed, see the code for documentation of the new API.
Most other questions about 2.x should be answered by looking over the documentation and the code. Please raise an issue if you have any problems with migrating.
Installation
- Add recaptcha to your
mix.exs
dependencies
defp deps do
[
{:recaptcha, "~> 3.0"},
]
end
- List
:recaptcha
as an application dependency
def application do
[ extra_applications: [:recaptcha] ]
end
- Run
mix do deps.get, compile
Config
By default the public and private keys are loaded via the RECAPTCHA_PUBLIC_KEY
and RECAPTCHA_PRIVATE_KEY
environment variables.
config :recaptcha,
public_key: {:system, "RECAPTCHA_PUBLIC_KEY"},
secret: {:system, "RECAPTCHA_PRIVATE_KEY"}
JSON Decoding
By default reCaptcha
will use Jason
to decode JSON responses, this can be changed as such:
config :recaptcha, :json_library, Poison
Usage
Render the Widget
Use raw
(if you're using Phoenix.HTML) and Recaptcha.Template.display/1
methods to render the captcha widget.
For recaptcha with checkbox
<form name="someform" method="post" action="/somewhere">
...
<%= raw Recaptcha.Template.display %>
...
</form>
For invisible recaptcha
<form name="someform" method="post" action="/somewhere">
...
<%= raw Recaptcha.Template.display(size: "invisible") %>
</form>
...
To change the position of the invisible recaptcha, use an option badge. See https://developers.google.com/recaptcha/docs/invisible on the date-badge.
Since recaptcha loads Javascript code asynchronously, you cannot immediately submit the captcha form. If 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. This can be done as follows:
<form name="someform" method="post" action="/somewhere">
...
<%= raw Recaptcha.Template.display(onload: "myOnLoadCallback") %>
</form>
...
And then in your JS code:
function myOnLoadCallback() {
// perform extra actions here
}
display
method accepts additional options as a keyword list, the options are:
Option | Action | Default |
---|---|---|
noscript |
Renders default noscript code provided by google | false |
public_key |
Sets key to the data-sitekey reCaptcha div attribute |
Public key from the config file |
hl |
Sets the language of the reCaptcha | en |
Verify API
Recaptcha provides the verify/2
method. Below is an example using a Phoenix controller action:
def create(conn, params) do
case Recaptcha.verify(params["g-recaptcha-response"]) do
{:ok, response} -> do_something
{:error, errors} -> handle_error
end
end
verify
method sends a POST
request to the reCAPTCHA API and returns 2 possible values:
{:ok, %Recaptcha.Response{challenge_ts: timestamp, hostname: host}}
-> The captcha is valid, see the documentation for more details.
{:error, errors}
-> errors
contains atomised versions of the errors returned by the API, See the error documentation 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.
verify
method also accepts a keyword list as the third parameter with the following options:
Option | Action | Default |
---|---|---|
timeout |
Time to wait before timeout | 5000 (ms) |
secret |
Private key to send as a parameter of the API request | Private key from the config file |
remote_ip |
Optional. The user's IP address, used by reCaptcha | no default |
Testing
In 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.
config :recaptcha,
secret: "6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe"
Setting up tests without network access can be done also. When configured as such a positive or negative result can be generated locally.
config :recaptcha,
http_client: Recaptcha.Http.MockClient,
secret: "6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe"
{:ok, _details} = Recaptcha.verify("valid_response")
{:error, _details} = Recaptcha.verify("invalid_response")
Contributing
Check out CONTRIBUTING.md if you want to help.
License
*Note that all licence references and agreements mentioned in the recaptcha README section above
are relevant to that project's source code only.