oakbotswat

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: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultCookieName = "HumanityToken"
	DefaultHeaderName = "HumanityToken"
)

Variables

View Source
var ErrCacheFull = errors.New("there are too many cache records")
View Source
var ErrTokenEmpty = errors.New("cannot recover request token proving humanity: token is empty")
View Source
var Template string

Functions

func NewErrorFromCodes

func NewErrorFromCodes(codes ...string) error

Types

type Cache

type Cache interface {
	GetToken(ctx context.Context, key string) (string, bool, error)
	SetToken(ctx context.Context, key, value string) 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 HumanityTokenExtractor added in v0.0.6

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

type MapCache

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

func NewMapCache

func NewMapCache(d time.Duration, recordLimit int) *MapCache

func (*MapCache) GetToken

func (m *MapCache) GetToken(ctx context.Context, key string) (string, bool, error)

func (*MapCache) SetToken

func (m *MapCache) SetToken(ctx context.Context, key, value string) error

type OakBotSWAT added in v0.0.6

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

func New

func New(withOptions ...Option) (b *OakBotSWAT, err error)

func (*OakBotSWAT) Gate added in v0.0.6

func (b *OakBotSWAT) Gate(onError oakhttp.Encoder) oakhttp.Middleware

func (*OakBotSWAT) IsHuman added in v0.0.6

func (b *OakBotSWAT) IsHuman(r *http.Request) error

IsHuman returns `nil` for human agents, an Error if humanity Verifier was not passed, or an [error] for any other condition. In rare cases when you need access to user data proven by the UI library, such as the Turnstile implementation, use that Verifier directly.

func (*OakBotSWAT) Middleware added in v0.0.6

func (b *OakBotSWAT) Middleware() oakhttp.Middleware

type Option

type Option func(*options) error

func WithCache

func WithCache(c Cache) Option

func WithCookieHumanityTokenExtractor added in v0.0.6

func WithCookieHumanityTokenExtractor(name string) Option

func WithDefaultCookieHumanityTokenExtractor added in v0.0.6

func WithDefaultCookieHumanityTokenExtractor() Option

func WithDefaultHeaderHumanityTokenExtractor added in v0.0.6

func WithDefaultHeaderHumanityTokenExtractor() Option

func WithHeaderHumanityTokenExtractor added in v0.0.6

func WithHeaderHumanityTokenExtractor(name string) Option

func WithHumanityTokenExtractor added in v0.0.6

func WithHumanityTokenExtractor(e HumanityTokenExtractor) Option

func WithVerifier

func WithVerifier(v Verifier) Option

type TemplateOption

type TemplateOption func(*TemplateOptions) error

func WithCookieDuration

func WithCookieDuration(d time.Duration) TemplateOption

func WithCookieName

func WithCookieName(name string) TemplateOption

func WithDescription

func WithDescription(description string) TemplateOption

func WithErrorURL

func WithErrorURL(URL string) TemplateOption

func WithLocale

func WithLocale(key string) TemplateOption

func WithTitle

func WithTitle(title string) TemplateOption

type TemplateOptions

type TemplateOptions struct {
	Locale         string
	Title          string
	Description    string
	ErrorURL       string
	CookieName     string
	CookieDuration time.Duration
}

func NewTemplateOptions

func NewTemplateOptions(all ...TemplateOption) (*TemplateOptions, error)

type UserData added in v0.0.6

type UserData struct {
	Data    string
	Expires time.Time
}

type Verifier

type Verifier interface {
	VerifyHumanityToken(
		ctx context.Context,
		clientResponseToken string,
		clientIPAddress string,
	) (
		userData string,
		err error,
	)
}

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

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