middlewares

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultHasAuthorizationConfig = HasAuthorizationConfig{
	JWTContextKey:   "user",
	AdminLevelClaim: "adm",
}
View Source
var DefaultReCAPTCHAConfig = ReCAPTCHAConfig{
	Skipper:   defaultSkipper,
	SecretKey: config.ServiceReCAPTCHASecretKey.GetString(),
	MinScore:  config.ServiceReCAPTCHAMinScore.GetFloat64(),
	FieldName: config.ServiceReCAPTCHAFieldName.GetString(),
}

DefaultReCAPTCHAConfig is the default configuration for the reCAPTCHA middleware

Functions

func ApplyReCAPTCHA added in v0.0.11

func ApplyReCAPTCHA(paths ...string) func(echo.Context) bool

ApplyReCAPTCHA returns a skipper that applies reCAPTCHA verification only to specific paths

func HasAuthorization added in v0.0.6

func HasAuthorization(level int32, scopes ...string) echo.MiddlewareFunc

func HasAuthorizationWithConfig added in v0.0.6

func HasAuthorizationWithConfig(config HasAuthorizationConfig, level int32, scopes ...string) echo.MiddlewareFunc

func ReCAPTCHA added in v0.0.11

func ReCAPTCHA() echo.MiddlewareFunc

ReCAPTCHA returns a middleware that validates Google reCAPTCHA v3 tokens

func ReCAPTCHAWithConfig added in v0.0.11

func ReCAPTCHAWithConfig(cfg ReCAPTCHAConfig) echo.MiddlewareFunc

ReCAPTCHAWithConfig returns a middleware with config that validates Google reCAPTCHA v3 tokens

func SkipReCAPTCHA added in v0.0.11

func SkipReCAPTCHA(paths ...string) func(echo.Context) bool

SkipReCAPTCHA returns a skipper that skips reCAPTCHA verification for specific paths

Types

type HasAuthorizationConfig added in v0.0.6

type HasAuthorizationConfig struct {
	JWTContextKey   string
	AdminLevelClaim string
}

type ReCAPTCHAConfig added in v0.0.11

type ReCAPTCHAConfig struct {
	// Skipper defines a function to skip middleware
	Skipper func(c echo.Context) bool

	// SecretKey is the Google reCAPTCHA v3 secret key
	SecretKey string

	// MinScore is the minimum score threshold (0.0 to 1.0)
	MinScore float64

	// FieldName is the field name in the JSON payload containing the reCAPTCHA token
	FieldName string
}

ReCAPTCHAConfig holds configuration for the reCAPTCHA middleware

type ReCAPTCHAResponse added in v0.0.11

type ReCAPTCHAResponse struct {
	Success     bool      `json:"success"`
	Score       float64   `json:"score"`
	Action      string    `json:"action"`
	ChallengeTS time.Time `json:"challenge_ts"`
	Hostname    string    `json:"hostname"`
	ErrorCodes  []string  `json:"error-codes,omitempty"`
}

ReCAPTCHAResponse represents the response from Google's reCAPTCHA API

type VerifyReCAPTCHAFunc added in v0.0.11

type VerifyReCAPTCHAFunc func(token, secretKey string) (*ReCAPTCHAResponse, error)

VerifyReCAPTCHAFunc defines the function signature for reCAPTCHA verification

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL