Languages
[Edit]
EN

reCAPTCHA v3 - simple example how to use in JavaScript and Spring Framework

19 points
Created by:
Root-ssh
178050

In this article we would like to show how to use Google reCAPTCHA v3 with JavaScript and Spring Framework (in Java).

The article consists of 3 parts:

  • Google reCAPTCHA v3 panel configuration example,
  • front-end code example,
  • back-end code example.

Official documentation of reCAPTCHA v3 can be found here.

 

Simple steps

Edit
  1. configure Google reCAPTCHA:
    1. go to Google reCAPTCHA panel
      https://www.google.com/recaptcha/admin#list
    2. create new configuration,
    3. type required data (check below screenshot):
      1. Label (configuration name),
      2. reCAPTCHA type as v3,
      3. Domain as my-domain.com and localhost for development,
    4. accept terms and Submit,
  2. integrate example codes with yours web site,
    1. copy source codes from the next sections,
    2. copy site key into index.html file (replace 2 times site_key_xxyyzz text - in script url and in variable):
    3. copy secret key into ReCAPTCHAv3Utils.java file:
  3. open in web browser your web page and check if everything is working correctly.

Notes:

  • protect yours secret key!
  • set double SCORES_LEVEL = 0.7 according to yours requirements (read comment in code)
  • sometimes it is good to do some action if bot behaving is detected (e.g. wait 60 seconds or confirm if you are not bot with yours email).

 

Google reCAPTCHA v3 panel example 

Edit

In this section we want to show example configuration for reCAPTCHA v3. Pay attention on localhost domain if you want to develop yours application with active reCAPTCHA.

reCAPTCHA v3 registration.
reCAPTCHA v3 registration.
site key + secret key for reCAPTCHA v3
site key + secret key for reCAPTCHA v3

 

Front-end with JavaScript example

Edit

In this section login action was used to present reCAPTCHA v3 usage with JavaScript. But we can change login string to anything different (check: ReCAPTCHAv3Utils.request('login', onSuccess, onError)).

index.html file:

 

Back-end with Spring Framework example

Edit

In this section, we can find all necessary files that are required to use reCAPTCHA v3 with Spring Framework.

It is necessary to create few files in a project and paste them content - the files are listed below.

pom.xml file (maven dependences):

UserController.java file:

LoginUserRequest.java file:

ReCAPTCHAv3Utils.java file:

ReCAPTCHAv3Exception.java file:

ReCAPTCHAv3Response.java file:

 

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join