Skip to content

A Vapor 3 library for validating Google reCAPTCHA submissions

Notifications You must be signed in to change notification settings

gotranseo/vapor-recaptcha

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vapor reCAPTCHA

Motivation

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

Installation

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.

Usage

Registering the Provider

In configure.swift, add this line:

let captchaConfig = CaptchaConfig(secretKey: "SECRET-KEY-FROM-GOOGLE")
services.register(CaptchaProvider(config: captchaConfig))

Usage

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 {
        // :(
    }
}

Author

Slate Solutions, Inc.

License

Vapor reCAPTCHA is available under the MIT license. See the LICENSE file for more info.