1.0.5 • Published 3 months ago

express-gg-recaptcha v1.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
3 months ago

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

: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

ping@steve-lebleu.dev

1.0.5

3 months ago

1.0.2

3 months ago

1.0.4

3 months ago

1.0.3

3 months ago

1.0.1

3 months ago

1.0.0

3 months ago