Class ReCaptchaConfig
This class holds the site key, secret key, and version used by all reCAPTCHA components
and verification calls in the application. Configure these values once during application
startup, typically in your Application.initialize() method.
Usage:
// In Application.initialize():
ReCaptchaConfig.setSiteKey("your-site-key");
ReCaptchaConfig.setSecretKey("your-secret-key");
// In createHead():
ReCaptchaConfig.addScript(head);
- Since:
- 1.0
- Version:
- 1.0
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddScript(com.oorian.html.elements.Head head) Adds the Google reCAPTCHA script to the page head.static StringReturns the configured secret key.static StringReturns the configured site key.static ReCaptchaVersionReturns the configured reCAPTCHA version.static voidsetSecretKey(String secretKey) Sets the reCAPTCHA secret key (private key).static voidsetSiteKey(String siteKey) Sets the reCAPTCHA site key (public key).static voidsetVersion(ReCaptchaVersion version) Sets the reCAPTCHA version to use.
-
Constructor Details
-
ReCaptchaConfig
public ReCaptchaConfig()
-
-
Method Details
-
setSiteKey
Sets the reCAPTCHA site key (public key).The site key is used in the browser to generate verification tokens. Obtain this from the reCAPTCHA admin console.
- Parameters:
siteKey- the reCAPTCHA v3 site key
-
setSecretKey
Sets the reCAPTCHA secret key (private key).The secret key is used server-side to verify tokens with Google's API. Obtain this from the reCAPTCHA admin console. This key must be kept confidential and never exposed to the client.
- Parameters:
secretKey- the reCAPTCHA v3 secret key
-
setVersion
Sets the reCAPTCHA version to use.Defaults to
ReCaptchaVersion.V3. Currently only v3 is supported by this library. Setting a deprecated version will have no effect on the script URL.- Parameters:
version- the reCAPTCHA version
-
getSiteKey
Returns the configured site key.- Returns:
- the reCAPTCHA site key
-
getSecretKey
Returns the configured secret key.- Returns:
- the reCAPTCHA secret key
-
getVersion
Returns the configured reCAPTCHA version.- Returns:
- the reCAPTCHA version
-
addScript
public static void addScript(com.oorian.html.elements.Head head) Adds the Google reCAPTCHA script to the page head.This method must be called in
createHead()for any page that uses theReCaptchacomponent. It loads the Google reCAPTCHA JavaScript API with the configured site key.- Parameters:
head- the page head element
-