Documentation
¶
Overview ¶
Package captchafox verifies tokens of the CaptchaFox widget with siteverify, with the secret key of a site.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client verifies tokens with the secret key of a site. It is safe for concurrent use; create it once and reuse it.
func NewClient ¶
NewClient returns a Client that gives a verification 5 seconds, from connecting to siteverify to the end of its answer. It returns an error if the secret key is empty.
func NewClientWithTimeout ¶
NewClientWithTimeout returns a Client that gives a verification the timeout instead of 5 seconds, from connecting to siteverify to the end of its answer. It returns an error if the secret key is empty or the timeout is not positive.
func (*Client) Verify ¶
Verify verifies a token. It returns *Passed or *Rejected; an empty token is rejected with missing-input-response without a request. Every error it returns is an *UnavailableError.
func (*Client) VerifyWith ¶
func (c *Client) VerifyWith(ctx context.Context, token, sitekey, remoteIP string) (Verification, error)
VerifyWith is Verify for a token that was issued for a site key to a visitor's IP address; it sends the site key and the IP address only when they are not empty.
type Passed ¶
type Passed struct {
// The time of the challenge as siteverify sent it, an ISO 8601 timestamp; empty if it sent none.
ChallengeTS string
// The hostname of the site where the challenge was solved; empty if siteverify sent none.
Hostname string
}
Passed means siteverify answered "success": true.
type Rejected ¶
type Rejected struct {
// The error codes of siteverify, such as timeout-or-duplicate; possibly none.
ErrorCodes []string
}
Rejected means siteverify answered "success": false, or the token was empty.
type UnavailableError ¶
type UnavailableError struct {
// contains filtered or unexported fields
}
UnavailableError means siteverify could not be evaluated: it was not reached, did not answer in time, answered with an HTTP status other than 200, or with a body that is no JSON object with a boolean success. Whether the protected request passes then is the caller's decision. Its message never contains the secret key.
func (*UnavailableError) Error ¶
func (e *UnavailableError) Error() string
func (*UnavailableError) Unwrap ¶
func (e *UnavailableError) Unwrap() error
Unwrap returns the error that made siteverify unavailable, such as that of the network or of a cancelled context.
type Verification ¶
type Verification interface {
// contains filtered or unexported methods
}
Verification is the outcome of a token that siteverify evaluated: *Passed or *Rejected, never both and nothing else. A token whose verification cannot be evaluated has no Verification; Verify returns an *UnavailableError instead.