1.1.0 • Published 9 years ago

google-recaptcha v1.1.0

Weekly downloads
5,438
License
MIT
Repository
github
Last release
9 years ago

Google Recaptcha

Build Status Codacy Badge Codacy Badge

A simple and framework agnostic way to verify Google Recaptcha data. This package currently supports Google Recaptcha V2.

Installation

$ yarn add google-recaptcha

Usage

const GoogleRecaptcha = require('google-recaptcha')

const googleRecaptcha = new GoogleRecaptcha({secret: 'RECAPTCHA_SECRET_KEY'})

// Some pseudo server code:

http.on('POST', (request, response) => {
  const recaptchaResponse = request.body['g-recaptcha-response']

  googleRecaptcha.verify({response: recaptchaResponse}, (error) => {
    if (error) {
      return response.send({isHuman: false})
    }

    return response.send({isHuman: true})
  })
})

Methods and Variables

constructor(Object options)

Creates an instance of the Google Recaptcha verifier. Here are the options:

  • String secret (required): Your Google Recaptcha secret key.
  • String apiUrl: The API URL to verify with. This option defaults to GoogleRecaptcha.DEFAULT_API_URL.
  • Object logger: Any console.log compatible logger. Defaults to using the debug package. The debug namespace is recaptcha.

googleRecaptcha.verify(Object options, Function callback)

Runs a verification of the Recaptcha response. Here are the options:

  • String response (required): The Recaptcha response token.
  • String remoteIp: The user's IP address.

The callback can take an Error error as its first parameter and a Object body as its second parameter. The body is a raw response from the Recaptcha verification. Specific details can be found here.

Static String GoogleRecaptcha.DEFAULT_API_URL

The default API URL to verify with. The value is https://www.google.com/recaptcha/api/siteverify.

License

Copyright (c) 2016 Martin Experiments LLC

MIT (http://www.opensource.org/licenses/mit-license.php)

1.1.0

9 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.0.4

12 years ago

0.0.3

12 years ago

0.0.2

12 years ago

0.0.1

12 years ago

0.0.0

12 years ago