JVM - Java / Kotlin / Groovy / Scala
The following tutorial will show you how to integrate Trustcaptcha into Java, Kotlin, Groovy or Scala.
Vorbereitung
Folgende Vorbereitungen sollten Sie treffen, bevor Sie mit der Implementierung von Trustcaptcha in Ihrem Java, Kotlin, Groovy or Scala Backend anfangen.
Requirements
- An account with Trustcaptcha and an existing CAPTCHA.
- A backend, into which Trustcaptcha is to be integrated.
Knowledge (recommended)
- Basic knowledge of the respective programming language.
- Understanding of the basic functionality of Trustcaptcha as well as the backend process.
Add Dependency
To use the Trustcaptcha library, you must first insert the corresponding dependencies into your project.
Build tools
Add the following dependency to your project using a build tool of your choice.
Use Library
Below you will find out how you can use the library.
Fetch Result
You can retrieve the verification result using the getVerificationResult() method of the CaptchaManager class from our servers. For this, you must provide your secret-keyue and the verification token.
Use Result
Once you have successfully retrieved the verification result, you can plan your next steps based on it. A concrete overview of all the information contained in the verification result and their respective meanings can be found in The Backend.
Example with Spring
The following example shows a possible implementation with the Spring Boot framework.
With a POST request to /api/example, the verification token is transmitted within the request body. Subsequently, the result is retrieved from the server. If the verification has not been passed or the bot score is above 0.5, a warning will be given as an example. Finally, the entire result is returned to the client.
The following model is used to transfer the verification token to the controller.
The entire example including source code can be found on Github.