Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/meyfa/recaptcha-promise
Node module for promise-based ReCAPTCHA verification
https://github.com/meyfa/recaptcha-promise
nodejs npm-package package promise recaptcha-promise recaptcha-verification
Last synced: about 1 month ago
JSON representation
Node module for promise-based ReCAPTCHA verification
- Host: GitHub
- URL: https://github.com/meyfa/recaptcha-promise
- Owner: meyfa
- License: mit
- Created: 2016-07-17T12:23:10.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2024-04-09T23:08:00.000Z (7 months ago)
- Last Synced: 2024-04-10T06:23:18.229Z (7 months ago)
- Topics: nodejs, npm-package, package, promise, recaptcha-promise, recaptcha-verification
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/recaptcha-promise
- Size: 743 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# recaptcha-promise
[![CI](https://github.com/meyfa/recaptcha-promise/actions/workflows/main.yml/badge.svg)](https://github.com/meyfa/recaptcha-promise/actions/workflows/main.yml)
[![Test Coverage](https://api.codeclimate.com/v1/badges/daa5cc798bbd3d7f17d0/test_coverage)](https://codeclimate.com/github/meyfa/recaptcha-promise/test_coverage)This Node module aims to provide simple, asynchronous, promise-based ReCAPTCHA
response verification. TypeScript type definitions are included._This software is in no way affiliated with or endorsed by Google._
## Installation
Add to your project's dependencies:
```sh
npm install recaptcha-promise
```## Usage
### Creating an instance
This is the recommended way. First, an instance is created with your secret key.
It can then be used to verify as many challenges as needed.```js
const recaptcha = require('recaptcha-promise').create({
secret: 'YOUR_SECRET_KEY'
})// In an HTTP handler:
// ... with Promises:
recaptcha.verify(userResponse).then(function (success) {
console.log(success ? 'Response valid' : 'Response invalid')
})// ... or in an async context:
async function handleRequest (userResponse) {
const success = await recaptcha.verify(userResponse)
console.log(success ? 'Response valid' : 'Response invalid')
}
handleRequest(/* ... */)
```### The global instance
This exists mostly for legacy reasons. If you do not want to dependency-inject
a custom object, you can configure this package with your secret key globally:```js
// note the missing .create(...) call
const recaptcha = require('recaptcha-promise')recaptcha.init({
secret: 'YOUR_SECRET_KEY' // secret_key and secretKey are also valid
})
```You can then use `recaptcha` exactly the same as above. You can also require it
elsewhere and it will still have the secret key ready.### Passing a remote address
If you have the client's remote address available, you can pass it as a second
parameter to the `verify` function.