Swiftpack.co - Mikroservices/Recaptcha as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Mikroservices.
Mikroservices/Recaptcha 2.1.0
:key: Google recaptcha library for Vapor
⭐️ 4
🕓 3 weeks ago
macOS
.package(url: "https://github.com/Mikroservices/Recaptcha.git", from: "2.1.0")

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.

GitHub

link
Stars: 4
Last commit: 3 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Dependencies

Release Notes

Add async/await support
3 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics