This library is a helper for Vapor 3 projects to validate form submissions using the Google reCAPTCHA platform.
To get started, you need to obtain a secret key from: https://www.google.com/recaptcha/admin
Vapor reCAPTCHA is available through SPM. To install it, simply add the following to your Package.swift
file:
.package(url: "https://github.com/gotranseo/vapor-recaptcha.git", from: "1.0.0")
Don't forget to also add it to dependencies array.
In configure.swift
, add this line:
let captchaConfig = CaptchaConfig(secretKey: "SECRET-KEY-FROM-GOOGLE")
services.register(CaptchaProvider(config: captchaConfig))
In your controller, you can do something like this:
let captchaResponse = ... //value from a submitted form
let googleCaptcha = try req.make(Captcha.self)
return googleCaptcha.validate(captchaFormResponse: captchaResponse).flatMap { success in
if success {
//celebrate!
} else {
// :(
}
}
Slate Solutions, Inc.
Vapor reCAPTCHA is available under the MIT license. See the LICENSE file for more info.