Giter VIP home page Giter VIP logo

kotlin-recaptcha-client's Introduction

kotlin-recaptcha-client

codecov

kotlin-recaptcha-client is a kotlin library for server side reCAPTCHA verification, it supports both recaptcha v2 and recaptcha v3.

"reCAPTCHA is a free CAPTCHA service that protects websites from spam and abuse."

Installation

WIP

Basic Usage

For v2 client:

import com.wusatosi.recaptcha.v2.RecaptchaV2Client

val v2Client = RecaptchaV2Client.create("your site secret")
runBlocking {
    // RecaptchaV2Client.verify is a suspend function
    val result: Boolean = v2Client.verify(token)

    // ...
}
v2Client.close()

For v3 client:

import com.wusatosi.recaptcha.v3.RecaptchaV3Client

val v3Client = RecaptchaV3Client.create("your site secret")
runBlocking {
    // RecaptchaV3Client.verify is a suspend function
    val result: Double = v3Client.verify(token)

    // ...
}
v3Client.close()

Configuring the client

Domain verification

Both V2 Client and V3 Client can be configured to restrict access to the website/ apk package for which the captcha was solved. The domain name is not verified by default.

RecaptchaV2Client.create("your site secret") {
    // Website domain:
    allowDomain("wusatosi.com", "google.com")
    allowDomains(listOf("github.com", "localhost"))

    // APK package domain:
    allowDomain("com.wusatosi.test")
}

Score Threshold and Action Verification (v3 only)

For v3 client, you can config a score threshold for verification.

RecaptchaV3Client.create("your site secret") {
    scoreThreshold = 0.8
}

You can limit the scope of actions you would like to limit.

RecaptchaV3Client.create("your site secret") {
    limitedActions("login")
    limitedActions("interact", "publish")
}

You can also supply a lambda that produces a score threshold depending on which action is reported.

RecaptchaV3Client.create("your site secret") {
    mapActionToThreshold {
        when (it) {
            // a higher threshold to essential operations
            "login" -> 0.8
            // a lower threshold to non-essential operations
            "post" -> 0.5
            // We reject any other actions
            else -> 5.0
        }
    }
}

Contributing

Issues and pull requests are all always welcome

Uses:

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.