turnstile

package
v0.0.0-...-39c7806 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package turnstile creates a secure by default humanity verifier backed by Cloudflare's Turnstile service.

On the client include the the following script:

<script src="https://challenges.cloudflare.com/turnstile/v0/api.js?onload=onloadTurnstileCallback" async defer></script>

Cloudflare Turnstile documentation: <https://developers.cloudflare.com/turnstile/>

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(withOptions ...Option) (botswat.Verifier, error)

Types

type Option

type Option func(*options) error

func WithAllowedActions

func WithAllowedActions(actions ...string) Option

func WithDefaultOptions

func WithDefaultOptions() Option

func WithEndpoint

func WithEndpoint(URL string) Option

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

func WithHostname

func WithHostname(name string) Option

func WithSecret

func WithSecret(key string) Option

type Request

type Request struct {
	// Secret key provided by Cloudflare.
	Secret string `json:"secret"`

	// Response key provided by the verification subject.
	Response string `json:"response"`

	// RemoteIP is the subject's IP address. It is optional but improves the verification accuracy.
	RemoteIP string `json:"remoteip"`
}

type Response

type Response struct {
	// Success is true if the verification passed.
	Success bool `json:"success"`

	// ChallengeTime when the verfication passed in ISO 8601 format.
	ChallengeTime string `json:"challenge_ts"`

	// Action name of the validation, set by the subject. Must match the information inside [Request.Response].
	Action string `json:"action"`

	// Hostname of the site that requested verification.
	Hostname string `json:"hostname"`

	// ErrorCodes of any problems that were encountered.
	//
	// https://developers.cloudflare.com/turnstile/get-started/server-side-validation/#error-codes
	ErrorCodes []string `json:"error-codes"`

	// CData is client subject data.
	CData string `json:"cdata"`
}

func (*Response) Time

func (r *Response) Time() (time.Time, error)

func (*Response) Validate

func (r *Response) Validate() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL