aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/go.jolheiser.com/hcaptcha
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/go.jolheiser.com/hcaptcha')
-rw-r--r--vendor/go.jolheiser.com/hcaptcha/.gitignore2
-rw-r--r--vendor/go.jolheiser.com/hcaptcha/LICENSE7
-rw-r--r--vendor/go.jolheiser.com/hcaptcha/Makefile13
-rw-r--r--vendor/go.jolheiser.com/hcaptcha/README.md9
-rw-r--r--vendor/go.jolheiser.com/hcaptcha/error.go41
-rw-r--r--vendor/go.jolheiser.com/hcaptcha/go.mod3
-rw-r--r--vendor/go.jolheiser.com/hcaptcha/hcaptcha.go105
-rw-r--r--vendor/go.jolheiser.com/hcaptcha/response.go10
8 files changed, 190 insertions, 0 deletions
diff --git a/vendor/go.jolheiser.com/hcaptcha/.gitignore b/vendor/go.jolheiser.com/hcaptcha/.gitignore
new file mode 100644
index 0000000000..a4539540fa
--- /dev/null
+++ b/vendor/go.jolheiser.com/hcaptcha/.gitignore
@@ -0,0 +1,2 @@
+# GoLand
+.idea/ \ No newline at end of file
diff --git a/vendor/go.jolheiser.com/hcaptcha/LICENSE b/vendor/go.jolheiser.com/hcaptcha/LICENSE
new file mode 100644
index 0000000000..0f02641b29
--- /dev/null
+++ b/vendor/go.jolheiser.com/hcaptcha/LICENSE
@@ -0,0 +1,7 @@
+Copyright 2020 John Olheiser
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file
diff --git a/vendor/go.jolheiser.com/hcaptcha/Makefile b/vendor/go.jolheiser.com/hcaptcha/Makefile
new file mode 100644
index 0000000000..5b4272f3ae
--- /dev/null
+++ b/vendor/go.jolheiser.com/hcaptcha/Makefile
@@ -0,0 +1,13 @@
+GO ?= go
+
+.PHONY: fmt
+fmt:
+ $(GO) fmt ./...
+
+.PHONY: test
+test:
+ $(GO) test -race ./...
+
+.PHONY: vet
+vet:
+ $(GO) vet ./... \ No newline at end of file
diff --git a/vendor/go.jolheiser.com/hcaptcha/README.md b/vendor/go.jolheiser.com/hcaptcha/README.md
new file mode 100644
index 0000000000..b13dc2d467
--- /dev/null
+++ b/vendor/go.jolheiser.com/hcaptcha/README.md
@@ -0,0 +1,9 @@
+# hCaptcha
+
+This library was based on the hCaptcha server-side verification [docs](https://docs.hcaptcha.com/#server).
+
+[Example](example_test.go)
+
+## License
+
+[MIT](LICENSE) \ No newline at end of file
diff --git a/vendor/go.jolheiser.com/hcaptcha/error.go b/vendor/go.jolheiser.com/hcaptcha/error.go
new file mode 100644
index 0000000000..6e4d165523
--- /dev/null
+++ b/vendor/go.jolheiser.com/hcaptcha/error.go
@@ -0,0 +1,41 @@
+package hcaptcha
+
+const (
+ ErrMissingInputSecret ErrorCode = "missing-input-secret"
+ ErrInvalidInputSecret ErrorCode = "invalid-input-secret"
+ ErrMissingInputResponse ErrorCode = "missing-input-response"
+ ErrInvalidInputResponse ErrorCode = "invalid-input-response"
+ ErrBadRequest ErrorCode = "bad-request"
+ ErrInvalidOrAlreadySeenResponse ErrorCode = "invalid-or-already-seen-response"
+ ErrSitekeySecretMismatch ErrorCode = "sitekey-secret-mismatch"
+)
+
+// ErrorCode is any possible error from hCaptcha
+type ErrorCode string
+
+// String fulfills the Stringer interface
+func (err ErrorCode) String() string {
+ switch err {
+ case ErrMissingInputSecret:
+ return "Your secret key is missing."
+ case ErrInvalidInputSecret:
+ return "Your secret key is invalid or malformed."
+ case ErrMissingInputResponse:
+ return "The response parameter (verification token) is missing."
+ case ErrInvalidInputResponse:
+ return "The response parameter (verification token) is invalid or malformed."
+ case ErrBadRequest:
+ return "The request is invalid or malformed."
+ case ErrInvalidOrAlreadySeenResponse:
+ return "The response parameter has already been checked, or has another issue."
+ case ErrSitekeySecretMismatch:
+ return "The sitekey is not registered with the provided secret."
+ default:
+ return ""
+ }
+}
+
+// Error fulfills the error interface
+func (err ErrorCode) Error() string {
+ return err.String()
+}
diff --git a/vendor/go.jolheiser.com/hcaptcha/go.mod b/vendor/go.jolheiser.com/hcaptcha/go.mod
new file mode 100644
index 0000000000..7306dc347d
--- /dev/null
+++ b/vendor/go.jolheiser.com/hcaptcha/go.mod
@@ -0,0 +1,3 @@
+module go.jolheiser.com/hcaptcha
+
+go 1.15
diff --git a/vendor/go.jolheiser.com/hcaptcha/hcaptcha.go b/vendor/go.jolheiser.com/hcaptcha/hcaptcha.go
new file mode 100644
index 0000000000..1f21f84008
--- /dev/null
+++ b/vendor/go.jolheiser.com/hcaptcha/hcaptcha.go
@@ -0,0 +1,105 @@
+package hcaptcha
+
+import (
+ "context"
+ "encoding/json"
+ "io/ioutil"
+ "net/http"
+ "net/url"
+ "strings"
+)
+
+const verifyURL = "https://hcaptcha.com/siteverify"
+
+// Client is an hCaptcha client
+type Client struct {
+ ctx context.Context
+ http *http.Client
+
+ secret string
+}
+
+// PostOptions are optional post form values
+type PostOptions struct {
+ RemoteIP string
+ Sitekey string
+}
+
+// ClientOption is a func to modify a new Client
+type ClientOption func(*Client)
+
+// WithHTTP sets the http.Client of a Client
+func WithHTTP(httpClient *http.Client) func(*Client) {
+ return func(hClient *Client) {
+ hClient.http = httpClient
+ }
+}
+
+// WithContext sets the context.Context of a Client
+func WithContext(ctx context.Context) func(*Client) {
+ return func(hClient *Client) {
+ hClient.ctx = ctx
+ }
+}
+
+// New returns a new hCaptcha Client
+func New(secret string, options ...ClientOption) (*Client, error) {
+ if strings.TrimSpace(secret) == "" {
+ return nil, ErrMissingInputSecret
+ }
+
+ client := &Client{
+ ctx: context.Background(),
+ http: http.DefaultClient,
+ secret: secret,
+ }
+
+ for _, opt := range options {
+ opt(client)
+ }
+
+ return client, nil
+}
+
+// Verify checks the response against the hCaptcha API
+func (c *Client) Verify(token string, opts PostOptions) (*Response, error) {
+ if strings.TrimSpace(token) == "" {
+ return nil, ErrMissingInputResponse
+ }
+
+ post := url.Values{
+ "secret": []string{c.secret},
+ "response": []string{token},
+ }
+ if strings.TrimSpace(opts.RemoteIP) != "" {
+ post.Add("remoteip", opts.RemoteIP)
+ }
+ if strings.TrimSpace(opts.Sitekey) != "" {
+ post.Add("sitekey", opts.Sitekey)
+ }
+
+ // Basically a copy of http.PostForm, but with a context
+ req, err := http.NewRequestWithContext(c.ctx, http.MethodPost, verifyURL, strings.NewReader(post.Encode()))
+ if err != nil {
+ return nil, err
+ }
+ req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
+
+ resp, err := c.http.Do(req)
+ if err != nil {
+ return nil, err
+ }
+
+ body, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ return nil, err
+ }
+ defer resp.Body.Close()
+
+ var response *Response
+ if err := json.Unmarshal(body, &response); err != nil {
+ return nil, err
+ }
+
+ return response, nil
+}
diff --git a/vendor/go.jolheiser.com/hcaptcha/response.go b/vendor/go.jolheiser.com/hcaptcha/response.go
new file mode 100644
index 0000000000..007276e6c1
--- /dev/null
+++ b/vendor/go.jolheiser.com/hcaptcha/response.go
@@ -0,0 +1,10 @@
+package hcaptcha
+
+// Response is an hCaptcha response
+type Response struct {
+ Success bool `json:"success"`
+ ChallengeTS string `json:"challenge_ts"`
+ Hostname string `json:"hostname"`
+ Credit bool `json:"credit,omitempty"`
+ ErrorCodes []ErrorCode `json:"error-codes"`
+}