Google Recaptcha - GetResponse returns no JSON

I am implementing a new login page for our site and one of the requirements is to have recaptcha on two elements in the form (one for registration, the other for getting username and password reminders).

I managed to get both recaptchas to work and they both work correctly. However, when I try to use recaptcha.getResponse () or use the recaptcha.render ('callback') method, it doesn't return JSON despite the spec says so. Here the bit

The response is a JSON object

{
    "success": true|false,
    "error-codes": [...]   // optional
}

      

In the returned data, I am not getting anything like this remotely. Instead, it looks to be Base64 encoded, but any decoder I have tried does not work. Looks like this

03AHJ_VuvWh4kgzEcKC_TBcc_BQjLucuL6g5tKXwYJT ... (much more after that)

Here is my code for performing recaptchas. It might sound like a mess, but it's just prototyping. Can anyone see if I am doing something wrong? I think I followed the spec exactly.

HTML (short for brevity)

<script type="text/javascript" src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit" async defer></script>

<div id="div_signup_recaptcha"></div>
<div id="div_forgotdetail_recaptcha"></div>

      

JS / JQuery

var grecaptchaSignup, grecaptchaForgotDetail;
var verifyForgotDetailCallback = function (response) {
    console.log(response);
}

var verifySignupCallback = function (response) {
    console.log(response);
}

var onloadCallback = function () {
    grecaptchaSignup = grecaptcha.render('div_signup_recaptcha', {
        'sitekey': 'mykey',
        'callback': verifySignupCallback
    });
    grecaptchaForgotDetail = grecaptcha.render('div_forgotdetail_recaptcha', {
        'sitekey': 'mykey',
        'callback': verifyForgotDetailCallback
    });
};

      

+3


source to share


1 answer


Okay, I'm an idiot.

I thought I read the spec correctly, it turns out I missed the main call to this url

https://www.google.com/recaptcha/api/siteverify?secret=your_secret&response=response_string&remoteip=user_ip_address



After I included my private key and encoded response, I got my JSON object.

Hope this clears up any confusion for other people in my position :(

+5


source







All Articles