hcaptcha

package
v0.19.4 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Verify

func Verify(ctx context.Context, response string) (bool, error)

Verify calls hCaptcha API to verify token

func WithContext

func WithContext(ctx context.Context) func(*Client)

WithContext sets the context.Context of a Client

func WithHTTP

func WithHTTP(httpClient *http.Client) func(*Client)

WithHTTP sets the http.Client of a Client

Types

type Client

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

Client is an hCaptcha client

func New

func New(secret string, options ...ClientOption) (*Client, error)

New returns a new hCaptcha Client

func (*Client) Verify

func (c *Client) Verify(token string, opts PostOptions) (*Response, error)

Verify checks the response against the hCaptcha API

type ClientOption

type ClientOption func(*Client)

ClientOption is a func to modify a new Client

type ErrorCode

type ErrorCode string

ErrorCode is any possible error from 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"
	ErrNotUsingDummyPasscode        ErrorCode = "not-using-dummy-passcode"
	ErrSitekeySecretMismatch        ErrorCode = "sitekey-secret-mismatch"
)

func (ErrorCode) Error

func (err ErrorCode) Error() string

Error fulfills the error interface

func (ErrorCode) String

func (err ErrorCode) String() string

String fulfills the Stringer interface

type PostOptions

type PostOptions struct {
	RemoteIP string
	Sitekey  string
}

PostOptions are optional post form values

type 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"`
}

Response is an hCaptcha response

Jump to

Keyboard shortcuts

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