Recaptcha

Go fiber recaptcha middleware

Install

1
go get github.com/akhmaos/go-fiber-recaptcha

Example

Set config

1
2
3
4
5
6
7
8
9
10
11
12
13
14

type Config struct {
ReCaptcha recaptcha.Config
}

func GetConfig() *Config {

conf := &Config{}

apiKey := os.Getenv("RECAPTCHA_API_KEY)
conf.ReCaptcha.ApiKey = apiKey
return conf
}

Fiber use case as middleware

1
2
3
4

conf := GetConfig()
app := fiber.New()
app.Use(recaptcha.New(conf.ReCaptcha))

Set Custom header

1
2
3
4
5
6
7
8
9
10
func GetConfig() *Config {

conf := &Config{}

apiKey := os.Getenv("RECAPTCHA_API_KEY)
conf.ReCaptcha.ApiKey = apiKey

conf.ReCaptcha.ReTokenHeader = "Custom-Header"
return conf
}

Set Custom Scope

1
2
3
4
5
6
7
8
9
10
func GetConfig() *Config {

conf := &Config{}

apiKey := os.Getenv("RECAPTCHA_API_KEY)
conf.ReCaptcha.ApiKey = apiKey

conf.ReCaptcha.Scope = 0.8
return conf
}

Set Custom Verify URL

1
2
3
4
5
6
7
8
9
10
func GetConfig() *Config {

conf := &Config{}

apiKey := os.Getenv("RECAPTCHA_API_KEY)
conf.ReCaptcha.ApiKey = apiKey

conf.ReCaptcha.VerifyUrl = "https://example.com/"
return conf
}
dark
sans