Socket
Socket
Sign inDemoInstall

recaptcha-node

Package Overview
Dependencies
1
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    recaptcha-node

A Node.js library to verify reCAPTCHA v2/v3 response tokens received from a client.


Version published
Weekly downloads
682
increased by33.73%
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

0.2.0 (2023-01-15)

⚠ BREAKING CHANGES

  • remove the Recaptcha._getPathname method

Code Refactoring

  • send sensitive data via the request body (f1adedf)

Readme

Source

recaptcha-node

A Node.js library to verify reCAPTCHA v2/v3 response tokens received from a client.

GitHub | NPM

Install

npm install recaptcha-node

Usage

Importing

If you are using reCAPTCHA v2, import the RecaptchaV2 class.

const {RecaptchaV2} = require('recaptcha-node');

If you are using reCAPTCHA v3, import the RecaptchaV3 class.

const {RecaptchaV3} = require('recaptcha-node');

Verifying a Response Token

To verify a response token using either RecaptchaV2 or RecaptchaV3, call the verify method.

The verify method's signature on RecaptchaV2 and RecaptchaV3 is nearly identical, differing only in the return value. RecaptchaV2's verify method returns an instance of RecaptchaV2Result, and RecaptchaV3's verify method returns an instance of RecaptchaV3Result.

const {RecaptchaV2} = require('recaptcha-node');

const recaptchaV2 = new RecaptchaV2('secretKey');

recaptchaV2.verify('responseToken')
.then(result => {
  if (result.success) {
    // reCAPTCHA response was valid.
  }
  else {
    // reCAPTCHA response was invalid.
  }
})
.catch(error =>  {
  // Request failed.
});

Configuration

The RecaptchaV2 and RecaptchaV3 classes can be initialized with an options object as the second argument.

const {RecaptchaV3} = require('recaptcha-node');

const recaptchaV3 = new RecaptchaV3('secretKey', {
  hostname: 'google.com',
  port: 443,
  protocol: 'https',
  timeout: 30 * 1000,
});
NameDefaultDescription
agentundefined
hostnamegoogle.comHostname that requests are made to
port80 if protocol is 'http', 443 if protocol is 'https'Port that requests are made to
protocol'https''https' or 'http'
timeout30000Milliseconds before a request times out. Setting to 0 will prevent the request from ever timing out

Objects

RecaptchaV2Result

PropertyTypeOptionalDescription
successbooleanfalseWhether this request was a valid reCAPTCHA token for your site
challengeTimestampDatefalseTimestamp of the challenge load
apkPackageNamestringtrueThe package name of the app where the reCAPTCHA was solved
hostnamestringtrueThe hostname of the site where the reCAPTCHA was solved
errorCodesstring[]true

RecaptchaV3Result

PropertyTypeOptionalDescription
successbooleanfalseWhether this request was a valid reCAPTCHA token for your site
scorenumberfalseThe score for this request (0.0 - 1.0)
actionstringfalseThe action name for this request
challengeTimestampDatefalseTimestamp of the challenge load
hostnamestringfalseThe hostname of the site where the reCAPTCHA was solved
errorCodesstring[]true

Keywords

FAQs

Last updated on 15 Jan 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc