Documentation
¶
Index ¶
- Variables
- func New(options ...func(*Config)) mist.Middleware
- func WithCookieDomain(domain string) func(*Config)
- func WithCookieMaxAge(maxAge time.Duration) func(*Config)
- func WithCookieName(name string) func(*Config)
- func WithCookiePath(path string) func(*Config)
- func WithCookieSameSite(sameSite http.SameSite) func(*Config)
- func WithCookieSecure(secure bool) func(*Config)
- func WithErrorHandler(handler func(ctx *mist.Context, err error)) func(*Config)
- func WithFormField(field string) func(*Config)
- func WithHeaderName(name string) func(*Config)
- func WithIgnoreMethods(methods []string) func(*Config)
- func WithTokenLength(length int) func(*Config)
- func WithTokenMode(mode TokenMode) func(*Config)
- func WithTokenRefreshInterval(interval time.Duration) func(*Config)
- func WithTokenTTL(ttl time.Duration) func(*Config)
- type Config
- type TokenData
- type TokenMode
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func WithCookieDomain ¶
WithCookieDomain 设置cookie域
func WithCookieMaxAge ¶
WithCookieMaxAge 设置cookie最大存活时间
func WithCookieSameSite ¶ added in v0.1.24
WithCookieSameSite 设置cookie的SameSite属性
func WithCookieSecure ¶
WithCookieSecure 设置cookie是否仅HTTPS
func WithErrorHandler ¶
WithErrorHandler 设置自定义错误处理
func WithIgnoreMethods ¶
WithIgnoreMethods 设置忽略的HTTP方法
func WithTokenLength ¶
提供配置选项函数 WithTokenLength 设置令牌长度
func WithTokenMode ¶ added in v0.1.24
WithTokenMode 设置令牌验证模式
func WithTokenRefreshInterval ¶ added in v0.1.24
WithTokenRefreshInterval 设置令牌刷新间隔
func WithTokenTTL ¶ added in v0.1.24
WithTokenTTL 设置令牌有效时间
Types ¶
type Config ¶
type Config struct {
// TokenLength 令牌长度,默认32字节
TokenLength int
// CookieName CSRF cookie名称,默认为"_csrf"
CookieName string
// CookiePath cookie路径,默认为"/"
CookiePath string
// CookieDomain cookie的域,可选
CookieDomain string
// CookieMaxAge cookie最大存活时间,默认为24小时
CookieMaxAge time.Duration
// CookieSecure 是否仅通过HTTPS发送cookie,默认为false
CookieSecure bool
// CookieHTTPOnly 是否禁止JavaScript访问cookie,默认为true
CookieHTTPOnly bool
// CookieSameSite SameSite属性,默认为Lax
CookieSameSite http.SameSite
// HeaderName 请求中CSRF头名称,默认为"X-CSRF-Token"
HeaderName string
// FormField 表单中CSRF字段名称,默认为"csrf_token"
FormField string
// ErrorHandler 自定义错误处理
ErrorHandler func(ctx *mist.Context, err error)
// IgnoreMethods 忽略的HTTP方法(默认忽略GET, HEAD, OPTIONS, TRACE)
IgnoreMethods []string
// TokenMode 令牌验证模式,默认为StandardMode
TokenMode TokenMode
// TokenTTL 令牌有效时间,默认为2小时,设置为0则永不过期
TokenTTL time.Duration
// TokenRefreshInterval 令牌刷新间隔,默认为30分钟,设置为0则不刷新
TokenRefreshInterval time.Duration
}
Config 配置CSRF保护
Click to show internal directories.
Click to hide internal directories.