Documentation ¶
Index ¶
- Constants
- func Setup(cfg *Config, httpClient HTTPClient)
- func SetupReCaptcha(url, secret string, httpClient HTTPClient)
- func SetupTwoFactor(timeStep int64, codeLength uint32, windowSize int)
- type Config
- type HTTPClient
- type ReCaptchaRequest
- type ReCaptchaResponse
- type ReCaptchaRiskAnalysis
- type ReCaptchaService
- type RecapEvent
- type TwoFactorAuth
- type TwoFactorOption
Constants ¶
View Source
const ( ActionLogin = "login" ActionSignup = "signup" ActionResetPwd = "password_reset" )
ReCaptcha 相关常量
Variables ¶
This section is empty.
Functions ¶
func SetupReCaptcha ¶
func SetupReCaptcha(url, secret string, httpClient HTTPClient)
SetupReCaptcha 初始化 reCAPTCHA 服务
func SetupTwoFactor ¶
SetupTwoFactor 初始化双因素认证服务
Types ¶
type Config ¶
type Config struct { ReCaptcha struct { URL string Secret string } TwoFactor struct { TimeStep int64 CodeLength uint32 WindowSize int } }
Config 配置结构
type HTTPClient ¶
HTTPClient 接口用于HTTP请求,方便测试时mock
type ReCaptchaRequest ¶
type ReCaptchaRequest struct {
Event RecapEvent `json:"event"`
}
ReCaptcha 请求结构
type ReCaptchaResponse ¶
type ReCaptchaResponse struct { Name string `json:"name"` RiskAnalysis ReCaptchaRiskAnalysis `json:"riskAnalysis"` TokenProperties struct { Valid bool `json:"valid"` InvalidReason string `json:"invalidReason"` Hostname string `json:"hostname"` AndroidPackageName string `json:"androidPackageName"` IosBundleId string `json:"iosBundleId"` Action string `json:"action"` CreateTime time.Time `json:"createTime"` } `json:"tokenProperties"` AccountDefenderAssessment struct { Labels []interface{} `json:"labels"` } `json:"accountDefenderAssessment"` Error *struct { Code int `json:"code"` Message string `json:"message"` Status string `json:"status"` } `json:"error"` }
ReCaptcha 响应结构
type ReCaptchaRiskAnalysis ¶
type ReCaptchaRiskAnalysis struct { Score float64 `json:"score"` Reasons []interface{} `json:"reasons"` ExtendedVerdictReasons []interface{} `json:"extendedVerdictReasons"` }
type ReCaptchaService ¶
type ReCaptchaService struct {
// contains filtered or unexported fields
}
ReCaptchaService 处理 Google reCAPTCHA 验证
func NewReCaptchaService ¶
func NewReCaptchaService(url, secret string, client HTTPClient) *ReCaptchaService
NewReCaptchaService 创建新的ReCaptchaService实例
type RecapEvent ¶
type TwoFactorAuth ¶
type TwoFactorAuth struct {
// contains filtered or unexported fields
}
TwoFactorAuth 处理双因素认证
func NewTwoFactorAuth ¶
func NewTwoFactorAuth(opts ...TwoFactorOption) *TwoFactorAuth
NewTwoFactorAuth 创建新的TwoFactorAuth实例
func (*TwoFactorAuth) GenerateQRCodeURL ¶
func (a *TwoFactorAuth) GenerateQRCodeURL(issuer, accountName, secret string) string
GenerateQRCodeURL 生成用于扫描的二维码URL
func (*TwoFactorAuth) GenerateSecret ¶
func (a *TwoFactorAuth) GenerateSecret() (string, error)
GenerateSecret 生成随机密钥
func (*TwoFactorAuth) VerifyCode ¶
func (a *TwoFactorAuth) VerifyCode(secret string, code int32) bool
VerifyCode 验证TOTP码
type TwoFactorOption ¶
type TwoFactorOption func(*TwoFactorAuth)
TwoFactorOption 定义TwoFactorAuth的可选配置
Click to show internal directories.
Click to hide internal directories.