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 ¶
- func NewGate(withOptions ...GateOption) (oakhttp.Encoder, error)
- type GateOption
- type Option
- func WithAllowedActions(actions ...string) Option
- func WithDefaultEndpoint() Option
- func WithDefaultHostname() Option
- func WithDefaultOptions() Option
- func WithDefaultSecretKey() Option
- func WithEndpoint(URL string) Option
- func WithHTTPClient(client *http.Client) Option
- func WithHostname(name string) Option
- func WithHostnameFromEnvironment(variableName string) Option
- func WithSecretKey(key string) Option
- func WithSecretKeyFromEnvironment(variableName string) Option
- type Request
- type Response
- type Turnstile
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 WithDefaultEndpoint ¶
func WithDefaultEndpoint() Option
func WithDefaultHostname ¶
func WithDefaultHostname() Option
func WithDefaultOptions ¶
func WithDefaultOptions() Option
func WithDefaultSecretKey ¶
func WithDefaultSecretKey() Option
func WithEndpoint ¶
func WithHTTPClient ¶
func WithHostname ¶
func WithSecretKey ¶
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"` }
type Turnstile ¶ added in v0.0.6
type Turnstile struct {
// contains filtered or unexported fields
}
func (*Turnstile) IsAllowedAction ¶ added in v0.0.6
Click to show internal directories.
Click to hide internal directories.