Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsBelowMinScore ¶
IsBelowMinScore reports whether the error returned from Result.Verify is due to the reCAPTCHA score being below the minimum.
Types ¶
type Response ¶
type Response struct {
// Success indicates whether the request was successful, it does not
// indicate the user should be allowed to continue with their action.
// See the Verify method.
Success bool `json:"success"`
// Score for this request (0.0 - 1.0).
Score float64 `json:"score"`
// Action name for this request (important to verify).
Action string `json:"action"`
// ChallengeTS contains the timestamp of the challenge load.
ChallengeTS time.Time `json:"challenge_ts"`
// Hostname of the site where the reCAPTCHA was solved.
Hostname string `json:"hostname"`
// ErrorCodes contains any errors with the request.
//
// Reference: https://developers.google.com/recaptcha/docs/verify/#error_code_reference
//
// Error code Description
// missing-input-secret The secret parameter is missing.
// invalid-input-secret The secret parameter is invalid or malformed.
// missing-input-response The response parameter is missing.
// invalid-input-response The response parameter is invalid or malformed.
// bad-request The request is invalid or malformed.
// timeout-or-duplicate The response is no longer valid: either is too old or has been used previously.
ErrorCodes []string `json:"error-codes"`
// contains filtered or unexported fields
}
Response represents the reCAPTCHA response from SiteVerify.
func SiteVerify ¶
SiteVerify makes a request to https://www.google.com/recaptcha/api/siteverify and returns the response. Use Response.Verify to verify the response.
The remoteIP parameter is optional and may be left blank. If you use a load balancer or another web server to proxy calls to your application make sure to get the correct remote IP. In your HTTP handler, r.RemoteAddr will be the IP of the server calling you, likely that of the load balancer or web server. Instead, use X-Real-IP or the first entry in X-Forwarded-For and make sure your load balancers and web servers are configured to set these headers correctly.
Example ¶
package main
import (
"context"
"fmt"
"log"
"github.com/blueskysystems/recaptchav3"
)
func main() {
var (
ctx = context.Background()
secretKey = "secret-key"
captchaResponse = "captcha-response"
remoteIP = ""
action = "homepage"
minScore = 0.5
hostnames []string = nil
)
response := recaptchav3.SiteVerify(ctx, secretKey, captchaResponse, remoteIP)
if err := response.Verify(action, minScore, hostnames); err != nil {
log.Fatal(err)
}
fmt.Println("OK")
}
Output: