Skip to content

Commit e6a268e

Browse files
committed
main commit
0 parents  commit e6a268e

5 files changed

+109
-0
lines changed

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) Dmitrii Kosenkov
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# reCAPTCHA Enterprise
2+
3+
reCAPTCHA Enterprise system for Common Lisp
4+
5+
## Installation
6+
7+
This system can be installed from [UltraLisp](https://ultralisp.org/) like this:
8+
9+
```common-lisp
10+
(ql-dist:install-dist "http://dist.ultralisp.org/"
11+
:prompt nil)
12+
(ql:quickload "recaptcha-enterprise")
13+
```
14+
15+
## Usage
16+
17+
```common-lisp
18+
(defpackage foo
19+
(:use :cl)
20+
(:local-nicknames (:re :recaptcha-enterprise)))
21+
22+
(setf re:*api-key* "API key associated with the current project")
23+
(setf re:*project-id* "your Google Cloud project ID")
24+
25+
(let ((response (re:verify "Key ID from project" "token")))
26+
(if (re:validp response)
27+
(format t "Recaptcha score: ~A" (re:score response))
28+
(format t "Recaptcha invalid, reason: ~A" (re:invalid-reason response))))
29+
```
30+

package.lisp

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(defpackage recaptcha-enterprise
2+
(:use #:cl)
3+
(:export #:verify
4+
#:event
5+
#:risk-analysis
6+
#:token-properties
7+
#:name
8+
#:validp
9+
#:invalid-reason
10+
#:score))

recaptcha-enterprise.asd

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(defsystem recaptcha-enterprise
2+
:version "0.1.0"
3+
:author "Dmitrii Kosenkov"
4+
:license "MIT"
5+
:depends-on ("dexador" "jonathan")
6+
:description "reCAPTCHA Enterprise system"
7+
:homepage "https://github.com/Junker/recaptcha-enterprise"
8+
:source-control (:git "https://github.com/Junker/recaptcha-enterprise.git")
9+
:components ((:file "package")
10+
(:file "recaptcha-enterprise")))

recaptcha-enterprise.lisp

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
(in-package #:recaptcha-enterprise)
2+
3+
(defparameter *api-key* nil
4+
"API key associated with the current project")
5+
(defparameter *project-id* nil
6+
"your Google Cloud project ID")
7+
8+
(defun verify (key-id token &optional (action "LOGIN"))
9+
(assert (not (null *api-key*)))
10+
(assert (not (null *project-id*)))
11+
(let* ((response (dex:post (format nil "https://recaptchaenterprise.googleapis.com/v1/projects/~A/assessments?key=~A"
12+
*project-id* *api-key*)
13+
:headers `(("Content-Type" . "application/json"))
14+
:content (jojo:to-json (list :|event| (list :|token| token
15+
:|siteKey| key-id
16+
:|expectedAction| action))))))
17+
(jojo:parse response)))
18+
19+
(defun risk-analysis (response)
20+
(getf :|riskAnalysis| response))
21+
22+
(defun token-properties (response)
23+
(getf :|tokenProperties| response))
24+
25+
(defun event (response)
26+
(getf :|event| response))
27+
28+
(defun name (response)
29+
(getf :|name| response))
30+
31+
(defun validp (response)
32+
(getf :|valid| (token-properties response)))
33+
34+
(defun invalid-reason (response)
35+
(getf :|invalidReason| (token-properties response)))
36+
37+
(defun score (response)
38+
(getf :|score| (risk-analysis response)))

0 commit comments

Comments
 (0)