turnstile

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2023 License: MIT Imports: 16 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 NewGate

func NewGate(withOptions ...GateOption) (oakhttp.Encoder, error)

Types

type GateOption

type GateOption func(*gateOptions) error

func WithDefaultSiteKey

func WithDefaultSiteKey() GateOption

func WithSiteAction

func WithSiteAction(action string) GateOption

func WithSiteKey

func WithSiteKey(key string) GateOption

func WithSiteKeyFromEnvironment

func WithSiteKeyFromEnvironment(variableName string) GateOption

func WithTemplateOptions

func WithTemplateOptions(options ...oakbotswat.TemplateOption) GateOption

type Option

type Option func(*options) error

func WithAllowedActions

func WithAllowedActions(actions ...string) Option

func WithDefaultEndpoint

func WithDefaultEndpoint() Option

func WithDefaultHostname

func WithDefaultHostname() Option

func WithDefaultOptions

func WithDefaultOptions() Option

func WithDefaultSecretKey

func WithDefaultSecretKey() Option

func WithEndpoint

func WithEndpoint(URL string) Option

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

func WithHostname

func WithHostname(name string) Option

func WithHostnameFromEnvironment

func WithHostnameFromEnvironment(variableName string) Option

func WithSecretKey

func WithSecretKey(key string) Option

func WithSecretKeyFromEnvironment

func WithSecretKeyFromEnvironment(variableName 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

type Turnstile added in v0.0.6

type Turnstile struct {
	// contains filtered or unexported fields
}

func New

func New(withOptions ...Option) (*Turnstile, error)

func (*Turnstile) IsAllowedAction added in v0.0.6

func (t *Turnstile) IsAllowedAction(name string) bool

func (*Turnstile) VerifyHumanityToken added in v0.0.6

func (t *Turnstile) VerifyHumanityToken(
	ctx context.Context,
	clientResponseToken string,
	clientIPAddress string,
) (
	userData string,
	err error,
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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