I'm working with RecaptchaV2, and using it as a first-step validation for authentication to my software. The authentication process typically looks like this:
Enter user ID > Validate recaptcha > Perform further authentication (configurable, e.g. passsword + 2fa)
Ideally, I would like to be able to detect user failure when performing the recpatcha, and perform a temporary lockout of the IP address or User ID when the user has failed too many times. It seems, however, that Recaptcha does not have a callback for failure cases, and only provides a "data-callback" parameter which is called on success. All validation seems to be entirely encapsulated within the widget, and my code is never informed of the status of the validation until it's successful.
My code is basically just the example from the documentation (https://developers.google.com/recaptcha/docs/display#auto_render), with some additional fanciness to automatically submit the form on the page when the recaptcha is completed. Here's the rough outline:
<div style="text-align: center" id="g-recaptcha-container">
<div class="g-recaptcha" data-sitekey="secret-site-key" data-callback="recaptcha2_success" style="display: inline-block"></div>
</div>
And my javascript:
function recaptcha2_success(response) {
var proceed = document.getElementById('g-recaptcha-proceed');
var form = document.getElementsByName('login-form');
// display the loading message
if (proceed !== undefined) {
proceed.style.display = 'block';
}
// submit the main form
if (form.length > 0) {
form[0].submit();
}
}
Does anyone have any suggestions? I can't find anything relevant in the developer documentation.