CaptchaFox (CaptchaFox v1.0.0)

Copy Markdown View Source

Verifies tokens of the CaptchaFox widget with siteverify, with the secret key of a site.

Create a client once with new/2 and reuse it; it holds no process and can be shared freely.

Summary

Functions

Creates a client with the secret key of the site.

Types

outcome()

@type outcome() ::
  {:ok, CaptchaFox.Passed.t() | CaptchaFox.Rejected.t()}
  | {:error, CaptchaFox.UnavailableError.t()}

t()

@opaque t()

verify_option()

@type verify_option() ::
  {:sitekey, String.t() | nil}
  | {:remote_ip, String.t() | :inet.ip_address() | nil}

Functions

new(secret, opts \\ [])

@spec new(String.t(), [{:timeout, pos_integer()}]) :: t()

Creates a client with the secret key of the site.

Options

  • :timeout - how long a verification may take in milliseconds, from connecting to siteverify to the end of its answer. Defaults to 5000.

Raises ArgumentError if the secret key is empty or no string, or the timeout is no positive integer.

verify(client, token, opts \\ [])

@spec verify(t(), String.t() | nil, [verify_option()]) :: outcome()

Verifies a token.

Returns {:ok, %CaptchaFox.Passed{}} or {:ok, %CaptchaFox.Rejected{}} when siteverify evaluated the token, and {:error, %CaptchaFox.UnavailableError{}} when siteverify cannot be evaluated. An empty or nil token is rejected with missing-input-response without a request.

Options

  • :sitekey - the site key the token was issued for; not sent when nil or empty.
  • :remote_ip - the IP address of the visitor, as a string or a tuple such as conn.remote_ip; not sent when nil or empty.

Raises ArgumentError if an argument has the wrong type, and RuntimeError if the operating system provides no CA certificates to check the certificate of siteverify with.