This is a Java client library for the Cloudflare Turnstile siteverify API. It provides a simple and efficient way to verify Turnstile tokens in your Java applications.
- Easy-to-use API for verifying Turnstile tokens
- Built with OkHttp for efficient HTTP requests
- Uses Jackson for JSON parsing
To use this library in your project, add the following dependency to your pom.xml
file:
<dependency>
<groupId>net.osslabz</groupId>
<artifactId>turnstile-siteverify-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
Here's a simple example of how to use the Cloudflare Turnstile Client:
import com.example.cloudflare.turnstile.TurnstileClient;
import com.example.cloudflare.turnstile.TurnstileResponse;
public class Example {
public static void main(String[] args) {
String secretKey = "your_secret_key_here";
TurnstileClient client = new TurnstileClient(secretKey);
try {
TurnstileResponse response = client.verify("turnstile_response_token");
if (response.isSuccess()) {
System.out.println("Verification successful!");
} else {
System.out.println("Verification failed: " + response.getErrorCodes());
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
You can customize the OkHttpClient
and ObjectMapper
used by the TurnstileClient
by using the appropriate constructor:
OkHttpClient customHttpClient = new OkHttpClient.Builder()
.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
.build();
ObjectMapper customObjectMapper = new ObjectMapper();
TurnstileClient client = new TurnstileClient(secretKey, customHttpClient, customObjectMapper);
To build the project, run:
mvn clean install
To run the tests, use:
mvn test
Contributions are welcome! Please feel free to submit a Pull Request.