RecaptchaService

Provides Google reCAPTCHA verification and HTML widget rendering for Ktor applications.

Includes server-side token verification via the Google reCAPTCHA API, a Ktor route-level validation extension, and kotlinx.html helpers for embedding the reCAPTCHA script and widget.

Types

Link copied to clipboard
@Serializable
data class RecaptchaResponse(val success: Boolean, val errorCodes: List<String> = emptyList(), val hostname: String? = null, val challengeTs: String? = null)

Represents the JSON response from Google's reCAPTCHA verification endpoint.

Functions

Link copied to clipboard

Adds the Google reCAPTCHA JavaScript to the HTML HEAD if reCAPTCHA is enabled and a site key is configured.

Link copied to clipboard
fun FlowContent.recaptchaWidget(config: RecaptchaConfig)

Renders the reCAPTCHA widget <div> in the HTML body if reCAPTCHA is enabled and a site key is configured.

Link copied to clipboard
suspend fun RoutingContext.validateRecaptcha(config: RecaptchaConfig, params: Parameters): Boolean

Validates the reCAPTCHA response token from form parameters within a Ktor RoutingContext.