Skip to content

Latest commit

 

History

History
48 lines (39 loc) · 1.36 KB

README.md

File metadata and controls

48 lines (39 loc) · 1.36 KB

Go Report Card Go Reference

recaptcha

The purpose of this package is to provide a simple interface to the Google reCAPTCHA V3 service for verifying requests server side in Golang.

Basic usage

For complete examples, please see the examples directory.

import "github.com/MicahParks/recaptcha"

Step 1: Create the verifier

// Create the verifier.
verifier := recaptcha.NewVerifierV3("mySecret", recaptcha.VerifierV3Options{})

Step 2: Verify the request with Google

// Verify the request with Google.
response, err := verifier.Verify(ctx, frontendToken, remoteAddr)
if err != nil {
    // Handle the error.
}

Step 3: Check the response

// Check the reCAPTCHA response.
err = response.Check(recaptcha.V3ResponseCheckOptions{
    Action:   []string{"submit"},
    Hostname: []string{"example.com"},
    Score:    0.5,
})
if err != nil {
    // Fail the request.
}

Test coverage

Test coverage is currently >90%.

References