a simple Clojure client for reCAPTCHA API (v1.0 and v2.0).
Include the library in your leiningen project dependencies:
[clj-recaptcha "0.0.3"]
To make the reCAPTCHA widget appear when your page loads, you will need to insert a snippet of JavaScript & non-JavaScript code in your <form>
element. To generate the snippet, use:
(ns your.namespace
(:require [clj-recaptcha.client :as c]))
(c/render "your-public-key" :ssl? true :display {:theme "clean" :lang "de"})
Optional parameters:
- :error - an error message to display (default nil)
- :ssl? - use HTTPS or HTTP? (default false)
- :noscript? - include content (default true)
- :display - a map of attributes for reCAPTCHA custom theming (default nil)
- :iframe-height - the height of noscript iframe (deafult 300)
- :iframe-width - the width of noscript iframe (default 500)
(ns your.namespace
(:require [clj-recaptcha.client-v2 :as c]))
(c/render "your-public-key")
After your page is successfully displaying reCAPTCHA, you need to configure your form to check whether the answers entered by the users are correct. Here's how it can be done:
(ns your.namespace
(:require [clj-recaptcha.client :as c]))
(c/verify "your-private-key" "challenge" "response" "127.0.0.1")
;; {:valid? false :error "incorrect-captcha-sol"}
Optional parameters:
- :ssl? - use HTTPS or HTTP? (default false)
- :proxy-host - a proxy host
- :proxy-port - a proxy port
- :connection-manager - a connection manager to be used to speed up requests
(ns your.namespace
(:require [clj-recaptcha.client-v2 :as c]))
(c/verify "your-private-key" "response" :remote-ip "127.0.0.1")
;; {:valid? false
;; :error "incorrect-captcha-sol"}
(c/verify "your-private-key" "another-response" :remote-ip "127.0.0.1")
;; {:valid? true
;; :error "incorrect-captcha-sol"
;; :score 0.8 ;; present in v3
;; :action "buy" ;; present in v3
;; :hostname "my-hostname" ;; present in v3
;; }
Optional parameters:
- :remote-ip - the IP address of the user who solved the CAPTCHA
- :proxy-host - a proxy host
- :proxy-port - a proxy port
- :connection-manager - a connection manager to be used to speed up requests
For better performance, you can use a pooled connection manager, that can be passed via :connection-manager option. To create a connection manager:
(create-conn-manager {:threads 5})
It's just a shortcut for clj-http.conn-mgr/make-reusable-conn-manager
, check clj-http documentation for more details.
Copyright © 2013 Pavel Prokopenko
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.