validateRecaptcha
Validates the reCAPTCHA response token from form parameters within a Ktor RoutingContext.
If reCAPTCHA is configured and the token is missing or invalid, this function responds with an HTTP 400 Bad Request and returns false. Returns true when validation succeeds or reCAPTCHA is not configured.
A token Google reports as valid must also pass the checks config configures: the hostname it was solved on (RecaptchaConfig.recaptchaExpectedHostnames) and, for reCAPTCHA v3, its score (RecaptchaConfig.recaptchaMinScore) and action (RecaptchaConfig.recaptchaExpectedAction). One that fails a check is treated like an invalid token.
Cancellation is not swallowed: if the call is cancelled while Google is being contacted, for example because the client disconnected, the kotlinx.coroutines.CancellationException propagates instead of being reported as a failed verification. A close made elsewhere while the request is starting does not cancel the caller: the verification is retried once with a new client, and fails if that one is closed too.
Return
true if validation passed or reCAPTCHA is disabled, false otherwise.
Parameters
the RecaptchaConfig providing keys and enabled status.
the form Parameters containing the g-recaptcha-response token.
Throws
if the surrounding coroutine is cancelled.