Package com.oorian.recaptcha
Class ReCaptchaVerifier
java.lang.Object
com.oorian.recaptcha.ReCaptchaVerifier
Server-side verification of Google reCAPTCHA v3 tokens.
This class sends the user's reCAPTCHA token to Google's verification API and checks
the response for success and score. The secret key must be configured via
ReCaptchaConfig.setSecretKey(String) before calling any verification methods.
Usage:
// Verify with a minimum score threshold
String token = params.getParameterValue("g-recaptcha-response");
boolean isHuman = ReCaptchaVerifier.verify(token, 0.5);
// Get the full verification response for detailed inspection
ReCaptchaResponse response = ReCaptchaVerifier.getResponse(token);
if (response.isSuccess() && response.getScore() >= 0.5)
{
// Process form
}
- Since:
- 1.0
- Version:
- 1.0
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ReCaptchaResponsegetResponse(String token) Gets the full verification response from the Google reCAPTCHA API.static booleanVerifies a reCAPTCHA token against the specified score threshold.
-
Constructor Details
-
ReCaptchaVerifier
public ReCaptchaVerifier()
-
-
Method Details
-
verify
public static boolean verify(String token, double scoreThreshold) throws com.oorian.apis.HttpRequestException Verifies a reCAPTCHA token against the specified score threshold.Sends the token to Google's verification API using the configured secret key. Returns
trueif the verification succeeds and the score meets or exceeds the threshold.- Parameters:
token- the reCAPTCHA token from the client (theg-recaptcha-responseparameter)scoreThreshold- the minimum acceptable score (0.0 to 1.0, where 1.0 is most likely human)- Returns:
trueif verification succeeds and the score meets the threshold- Throws:
com.oorian.apis.HttpRequestException- if an error occurs communicating with the Google API
-
getResponse
public static ReCaptchaResponse getResponse(String token) throws com.oorian.apis.HttpRequestException Gets the full verification response from the Google reCAPTCHA API.This method provides access to all fields returned by the API, including the score, action name, challenge timestamp, hostname, and any error codes. Use this method when you need more detail than the simple pass/fail of
verify(String, double).- Parameters:
token- the reCAPTCHA token from the client- Returns:
- the full verification response
- Throws:
com.oorian.apis.HttpRequestException- if an error occurs communicating with the Google API
-