Skip to content

Repository files navigation

CaptchaKit

Lightweight and asynchronous Swift package for server-side verification of various CAPTCHA tokens.

Services

  • Google reCAPTCHA1
  • hCaptcha2
  • Cloudflare Turnstile3

Installation

Add CaptchaKit to your project's dependencies in Package.swift:

.package(url: "https://github.com/mikuwithbeer/CaptchaKit.git", from: "2.0.0")

Usage

  1. Create a reusable client instance:

    import CaptchaKit
    
    let client = CaptchaKit.Client(
      CaptchaKit.Config(
        strategy: .turnstile,
        secret: "your-secret-key"
      )
    )
  2. Verify token with existing client:

    let isValid = await client.isValid("user-token")
    if !isValid {
        // Unauthorized!
    }

    Alternatively, you can verify with metadata:

    if let verification = try? await client.verifyDetails("user-token", ip: "100.200.255.1") {
        print("Verified for \(verification.host) at \(verification.date)")
    }

Appendix

This project is licensed under the BSD-2-Clause Plus Patent License4.

Footnotes

  1. https://developers.google.com/recaptcha

  2. https://www.hcaptcha.com

  3. https://www.cloudflare.com/products/turnstile/

  4. https://spdx.org/licenses/BSD-2-Clause-Patent.html

Releases

Contributors

Languages