captcha

package
v0.0.0-...-d879545 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultProviderName = "captcha"
)

Variables

View Source
var (
	ErrCaptchaFailed   = errors.New("captcha failed")
	ErrCaptchaRequired = errors.New("captcha required")
)

Functions

func Registrate

func Registrate(ctx context.Context, cfg *Config) (context.Context, error)

Types

type AccpClaimsExample

type AccpClaimsExample struct {
	*jwt.StandardClaims
	TokenType string
}

type Config

type Config struct {
	// JWT token TTL
	TokenTTL time.Duration
	// JWT token sign
	TokenSign string
	// Google verify URL
	VerifyURL string
	// Google captcha secret key
	Key string
	// Header is name of header in request for captcha
	Header helper.Arguments
	// Cookie is name of cookie in request for captcha
	Cookie helper.Arguments
	// Pool is config for http clients pool
	Pool *httpclient.Config
}

Config is config structure for captcha

func (*Config) SetDefault

func (c *Config) SetDefault()

func (*Config) Validate

func (c *Config) Validate() error

type GoogleCaptcha

type GoogleCaptcha struct {
	// contains filtered or unexported fields
}

func Get

func Get(ctx context.Context) *GoogleCaptcha

func NewGoogleCaptcha

func NewGoogleCaptcha(ctx context.Context, cfg *Config) (*GoogleCaptcha, error)

func (*GoogleCaptcha) GenerateCaptchaJWT

func (g *GoogleCaptcha) GenerateCaptchaJWT(w http.ResponseWriter) error

func (*GoogleCaptcha) Validate

func (g *GoogleCaptcha) Validate(r *http.Request) (SrcCaptcha, error)

type GoogleRecaptchaResponse

type GoogleRecaptchaResponse struct {
	Success            bool     `json:"success"`
	ChallengeTimestamp string   `json:"challenge_ts"`
	Hostname           string   `json:"hostname"`
	ErrorCodes         []string `json:"error-codes"`
}

type SrcCaptcha

type SrcCaptcha int
const (
	CaptchaSrcUnknown SrcCaptcha = iota
	CaptchaFromClient
	CaptchaFromGoogle
)

Jump to

Keyboard shortcuts

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