0

I need to integrate recaptcha v3 with my jsp site. It's just a login page which is sending data to another endpoint after clicking Login button. FOr PoC I was able to add recaptcha on page and get token when page is load. Then I was able to verify it.

I would like now to get token and verify it at the moment when user click Login button. So I add onclick event on button and assign my function there:

function verifyCaptcha() {
        grecaptcha.ready(function() {
            grecaptcha.execute('sitekey', {action: 'submit'}).then(function (token) {
                checkCaptcha(token);
            });
        });
    }

But after I click Login it doesn't go inside grecaptcha.ready function. What I did wrong here?

chastain
  • 69
  • 8

1 Answers1

0

Every time the page reloads you get a new token from google . You can use that token only once . Somehow if you are using that token more than once to get the response from google Api , you will get that error .

The trick is , you should send the token to the server via ajax request(Page load) and save the token in a server variable. Then, in the time of form submission use that token to verify that reCapcha .

Nihar Sarkar
  • 1,187
  • 1
  • 13
  • 26