google-recaptcha-api

    1.0.0 • Public • Published

    google-recaptcha-api

    A simple library of captcha based on Google reCAPTCHA Server API that supports Node.js.

    Install

    Using npm

    npm install google-recaptcha-api --save

    Usage

    Node.js usage

    You can use google-recaptcha-v2 in browser.

    const GoogleReCaptcha = require('google-recaptcha-api');
    const captcha = new GoogleReCaptcha('your_server_captcha_key');
    try {
        const res = await captcha.validate('captcha_token', 'user_ip');
        if (res.success) {
            //The response token is valid.
        } else {
            //The response token is invalid.
        }
    } catch(e) {
        //Some exception, such as network error => request timeout.
    }
    

    You can get server_captcha_key from Google reCAPTCHA Admin Console.

    Method

    new GoogleReCaptcha(secret, host) => Create an instance of google-recaptcha-api.

    • secret => required, the shared key between your site and reCAPTCHA.
    • host => optional, API hostname, default value is www.google.com. Specially, some areas require network proxying, such as China, just set www.recaptcha.net.

    instance.validate(response, remoteip) => Using the following API to ensure the response token is valid. Return value is a promise, you can use async-await synchronizing code.

    • response => required, the user response token provided by the reCAPTCHA client-side integration on your site.
    • remoteip => required, the user's IP address.

    License

    google-recaptcha-api is MIT licensed.

    Install

    npm i google-recaptcha-api

    DownloadsWeekly Downloads

    1

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    4.98 kB

    Total Files

    6

    Last publish

    Collaborators

    • amoydreamer