Recaptcha

master

:key: Google recaptcha library for Vapor
Mikroservices/Recaptcha

Recaptcha

Build Status Swift 5.2 Vapor 4 Swift Package Manager Platforms OS X | Linux

Library is prepared for support Google Recaptcha service to Vapor applications. First you need to obtain a secret key from: https://www.google.com/recaptcha/admin.

Most part of the code was originally created here: gotranseo/vapor-recaptcha.

Getting started

You need to add library to Package.swift file:

  • add package to dependencies:
.package(url: "https://github.com/Mikroservices/Recaptcha.git", from: "2.0.0")
  • and add product to your target:
.target(name: "App", dependencies: [
    .product(name: "Vapor", package: "vapor"),
    .product(name: "Recaptcha", package: "Recaptcha")
])

Set the Recaptcha configuration (e.g. in main.swift file).

import App
import Vapor
import Recaptcha

var env = try Environment.detect()
try LoggingSystem.bootstrap(from: &env)

let app = Application(env)
defer { app.shutdown() }

// Recaptcha.
app.captcha.configuration.secretKey = "SecretKey"

try configure(app)
try app.run()

Using Recaptcha client in your controller.

app.get("recaptcha") { req -> EventLoopFuture<String> in
    let captchaToken = try req.query.get(String.self, at: "captchaToken")

    let validationFuture = req.validate(captchaFormResponse: captchaToken)
    return validationFuture.map { result -> String in
        return result ? "Recaptcha ok" : "Recaptcha failed"
    }
}

Developing

Download the source code and run in command line:

$ git clone https://github.com/Mikroservices/Recaptcha.git
$ swift package update
$ swift build

Run the following command if you want to open project in Xcode:

$ open Package.swift

Contributing

You can fork and clone repository. Do your changes and pull a request.

Description

  • Swift Tools 5.2.0
View More Packages from this Author

Dependencies

Last updated: Fri Oct 18 2024 04:41:31 GMT-0900 (Hawaii-Aleutian Daylight Time)