npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-gg-recaptcha

v1.0.5

Published

Express.js middleware for back-end to back-end Google recpatcha V3 token validation.

Downloads

32

Readme

GitHub Release Github action workflow status Coverage Status CodeFactor GitHub License

Google ReCaptcha V3 middleware for Express.js

Endpoint protection using express validation midlleware.

Middleware illustration

Prerequisites

  • A project in https://www.google.com/recaptcha/admin/.
  • A domain name whitelisted in this project.
  • A Google recaptcha front-end integration in order to call your backend, who's call the Google API.

:link: Google official documentation

How to ?

1. Import re-captcha middleware

const { verifyGGRecaptchaV3 } = require('express-gg-recaptcha');

2. Plug re-captcha middleware generator on the endpoint to protect

app.use('/protected-path', verifyGGRecaptchaV3(secret, score, logger), controllerAction);

The function takes one required and two optional parameters:

  • secret - Google recaptcha secret - Required
  • score - Minimal score to consider token as valid, between 0 and 1 - Optional - Default: 0.7
  • logger - A local logger who's can be useful to debug - Optional - Default process.stdout

The middleware throws an error when:

  • secret is not provided or with an invalid format
  • score is provided explicitely but invalid

3. Do request

The middleware expects the token to verify on the request body, plugged on req.body.token.

$ curl --url "https://domain.com/protected-path" --data "token=ggtoken&param=..."

The middleware calls next:

  • with a 401 Error if the token verification fails
  • with a catched Error if an unexpected error occurs
  • with nothing in case of success

In case of success, the token is removed from the req.body object before to call next.

Tests

$ npm run test

License

MIT

Contact

[email protected]