Socket
Socket
Sign inDemoInstall

node-grecaptcha-verify

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    node-grecaptcha-verify

Simple reCAPTCHA verifier for node


Version published
Weekly downloads
85
decreased by-74.32%
Maintainers
1
Install size
10.3 kB
Created
Weekly downloads
 

Readme

Source

reCAPTCHA verification helper for node

Implementation of Google reCAPTCHA verify for nodeJS, written in TypeScript. No dependencies. This lib targets reCAPTCHA v3.

Installation

You need to register your website for Google reCAPTCHA to obtain a pair of keys first. Google will give you a SITE KEY and a SECRET KEY. The SITE KEY is used on your website to request a token. To verify the token with this lib, you must use the SECRET KEY.

Install the npm package:

$ npm i --save node-grecaptcha-verify

Usage:


import {ReCAPTCHA} from "node-grecaptcha-verify";

const reCaptcha = new ReCAPTCHA(reCaptchaSecret, parseFloat(process.env.RECAPTCHA_MIN_SCORE));
const verificationResult = await reCaptcha.verify(token);

if (true === verificationResult.isHuman) {
    // requested by a human
} else {
    // requested by a bot
}

If you want to know what Google answered (e.g. to check for errors or get the score):


// get the score
const score = verificationResult.score;

// get errors
const errors = verificationResult.errors;


By default, a score lower than 0.5 is considered a bot. You can set your own threshold by setting it in the constructor. You can also control if the action should be respected and checked.


// set the minimum score for humans to 0.7 (defaults to 0.5)
const reCaptcha = new ReCAPTCHA(<YOUR SITE KEY>, 0.7);

// tell the lib to check if the action matches (the action you sent to reCAPTCHA in the frontend to obtain the token)
const reCaptcha = new ReCAPTCHA(<YOUR SITE KEY>, 0.7);
const isHuman = await reCaptcha.verify(<TOKEN>, <ACTION>);

License

MIT License

Keywords

FAQs

Last updated on 30 Jul 2019

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