Go to file
Artur b40f0ac185 Update to master branch 2019-10-03 16:09:07 +03:00
.github/ISSUE_TEMPLATE Update issue template to include ReCaptcha v2 docs 2019-04-04 17:21:28 -03:00
Example Fix webview's resource loading detection 2018-12-06 15:53:51 -02:00
ReCaptcha Added possibility to observe loading state changing 2019-06-17 19:32:23 +03:00
ReCaptcha-Carthage Carthage support 2017-10-19 10:42:34 -02:00
ReCaptcha-Carthage.xcodeproj Updates to support Swift 4.2. (#52) 2018-09-26 15:26:52 -03:00
ReCaptcha_RxSwift Carthage support 2017-10-19 10:42:34 -02:00
fastlane Fix Fastlane test devices 2018-11-12 15:02:34 -02:00
.gitignore Updating documentation 2018-11-12 14:15:57 -02:00
.gitmodules Fix: Running Fastlane with a single device 2017-11-13 16:42:39 -02:00
.jazzy.yaml Adding jazzy config file 2018-09-06 16:14:53 -03:00
.swiftlint.yml Updating docs license year 2018-01-29 12:37:52 -02:00
.travis.yml Updates to support Swift 4.2. (#52) 2018-09-26 15:26:52 -03:00
CHANGELOG.md Version Bump (1.4.2) 2018-12-06 16:02:45 -02:00
Cartfile Update to master branch 2019-10-03 16:09:07 +03:00
Cartfile.resolved Update to master branch 2019-10-03 16:09:07 +03:00
Gemfile Updates to support Swift 4.2. (#52) 2018-09-26 15:26:52 -03:00
Gemfile.lock Updates to support Swift 4.2. (#52) 2018-09-26 15:26:52 -03:00
LICENSE Version Bump 2018-01-10 13:16:23 -02:00
README.md Add incompatibility with ReCaptcha v3 to README 2019-04-04 17:17:42 -03:00
ReCaptcha.podspec Version Bump (1.4.2) 2018-12-06 16:02:45 -02:00
_Pods.xcodeproj Initial code 2017-04-11 15:00:44 -03:00
codecov.yml Fix: Codecov range 2017-11-13 16:43:09 -02:00
example-v2-key.png Add incompatibility with ReCaptcha v3 to README 2019-04-04 17:17:42 -03:00
example.gif Adding gif to README 2017-04-18 15:54:02 -03:00
example2.gif Adding new example gif 2017-07-14 11:48:52 -04:00
pre-push.sh Fix: Running Fastlane with a single device 2017-11-13 16:42:39 -02:00

README.md

ReCaptcha

Build Status Version License Platform codecov Carthage compatible


Add Google's Invisible ReCaptcha v2 to your project. This library automatically handles ReCaptcha's events and retrieves the validation token or notifies you to present the challenge if invisibility is not possible.

Example Gif 2 Example Gif

Warning ⚠️

Beware that this library only works for ReCaptcha v2 Invisible keys! Make sure to check the reCAPTCHA v2 Invisible badge option when creating your API Key.

ReCaptcha v2 invisible key example

You won't be able to use a ReCaptcha v3 key because it requires server-side validation. On v3, all challenges succeed into a token which is then validated in the server for a score. For this reason, a frontend app can't know on its own wether or not a user is valid since the challenge will always result in a valid token.

Installation

ReCaptcha is available through CocoaPods and Carthage. To install it, simply add the following line to your dependencies file:

Cocoapods

pod "ReCaptcha"
# or
pod "ReCaptcha/RxSwift"

Carthage

github "fjcaetano/ReCaptcha"

Carthage will create two different frameworks named ReCaptcha and ReCaptcha_RxSwift, the latter containing the RxSwift extension for the ReCaptcha framework.

Usage

Simply add ReCaptchaKey and ReCaptchaDomain (with a protocol ex. http:// or https://) to your Info.plist and run:

let recaptcha = try? ReCaptcha()

override func viewDidLoad() {
    super.viewDidLoad()

    recaptcha?.configureWebView { [weak self] webview in
        webview.frame = self?.view.bounds ?? CGRect.zero
    }
}


func validate() {
    recaptcha?.validate(on: view) { [weak self] (result: ReCaptchaResult) in
        print(try? result.dematerialize())
    }
}

You can also install the reactive subpod and use it with RxSwift:

recaptcha.rx.validate(on: view)
    .subscribe(onNext: { (token: String) in
        // Do something
    })

Alternte endpoint

If your app has firewall limitations that may be blocking Google's API, the JS endpoint may be changed on initialization. It'll then point to https://www.recaptcha.net/recaptcha/api.js:

public enum Endpoint {
    case default, alternate
}

let recaptcha = try? ReCaptcha(endpoint: .alternate) // Defaults to `default` when unset

Help Wanted

Do you love ReCaptcha and work actively on apps that use it? We'd love if you could help us keep improving it! Feel free to message us or to start contributing right away!

Full Documentation

License

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