Git Product home page Git Product logo

fiber-recaptcha's Introduction

Golang Fiber reCAPTCHA middleware

Go Report Card Go Coverage Build Status Maintainability contributions welcome

Golang reCAPTCHA middleware for Fiber. This package takes care of getting the g-recaptcha-response field from the sent form (or other request) data and validating the reCAPTCHA using Google's API.

This package should support at least these types of reCAPTCHA:

  • reCAPTCHA V2, "I'm not a robot" Checkbox
  • reCAPTCHA V2, Invisible reCAPTCHA badge

Installation

You can add this package to your code by two simple steps, which are:

  1. get the package by go get github.com/jansvabik/fiber-recaptcha
  2. import the package manually by importing github.com/jansvabik/fiber-recaptcha or by calling the exported Middleware(c *fiber.Ctx) error function from inside of the package

Usage

To use the middleware within your web server, you should add the Middleware function to the queue of functions in your Fiber router, like in this example:

// pass your secret key to the package
recaptcha.SecretKey = "place-your-recaptcha-secret-key-here"

// create new fiber router
router := fiber.New()

// create an endpoint with the recaptcha middleware
router.Post("/endpoint", recaptcha.Middleware, endpoint.YourHandler)

When there is a request to this endpoint, for first it will go through this reCAPTCHA middleware which sends a request to the Google API and validates the whole request to be sent by human or by robot (depending to the Google response). Then, it sets up a local variable recaptchaSuccess with boolean value which you can access and use in an if statement.

// test the recaptcha success in your endpoint handler
if c.Locals("recaptchaSuccess") == false {
    // code to do if the validation fails
}

// do other job if the validation succeeds

There are only two possible values which can appear in the local variable:

  • boolean true if the validation succeeds
  • boolean false if the validation fails

fiber-recaptcha's People

Contributors

jansvabik avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

benemohamed

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.