botswat

package module
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: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotHuman = errors.New("robot detected")

Functions

func New

func New(withOptions ...Option) (oakhttp.Middleware, error)

func NewErrorFromCodes

func NewErrorFromCodes(codes ...string) error

Types

type Botswat

type Botswat interface {
	ResponseTokenPrompt() []byte

	// VerifyResponseToken should return `nil` for valid tokens, [ErrNotHuman] for rejected tokens, or an [Error] for any other condition.
	//
	// A response may only be validated once. If the same response is presented twice, the second and each subsequent request will generate an error stating that the response has already been consumed.
	VerifyResponseToken(
		ctx context.Context,
		clientToken string,
		clientIPAddress string,
	) error
}

type Cache

type Cache func(Verifier) Verifier

type CacheAdaptor

type CacheAdaptor interface {
	Get(context.Context, []byte) ([]byte, error)
	Set(context.Context, []byte, []byte) error
}

type Error

type Error string
const (
	ErrMissingInputSecret   Error = "missing-input-secret"
	ErrInvalidInputSecret   Error = "invalid-input-secret"
	ErrMissingInputResponse Error = "missing-input-response"
	ErrInvalidInputResponse Error = "invalid-input-response"
	ErrBadRequest           Error = "bad-request"
	ErrTimeoutOrDuplicate   Error = "timeout-or-duplicate"
	ErrInternalError        Error = "internal-error"
)

func (Error) Error

func (err Error) Error() string

type Option

type Option func(*options) error

func WithCache

func WithCache(c Cache) Option

func WithCacheAdaptor

func WithCacheAdaptor(adaptor CacheAdaptor) Option

func WithCookieResponseExtractor

func WithCookieResponseExtractor(name string) Option

func WithDefaultOptions

func WithDefaultOptions() Option

func WithResponseExtractor

func WithResponseExtractor(e ResponseExtractor) Option

func WithVerifier

func WithVerifier(v Verifier) Option

type ResponseExtractor

type ResponseExtractor func(
	r *http.Request,
) (
	clientResponseToken string,
	err error,
)

type Verifier

type Verifier func(
	ctx context.Context,
	clientResponseToken string,
	clientIPAddress string,
) (
	userData string,
	err error,
)

Verifier returns ErrNotHuman if client response was not recognized as valid.

A response may only be validated once. If the same response is presented twice, the second and each subsequent request will generate an error stating that the response has already been consumed.

Directories

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

Jump to

Keyboard shortcuts

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