Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewToken ¶
func NewToken(entity AuthInterface, key interface{}) (string, error)
NewToken 根据传入的结构体(非空结构体)返回一个token
Types ¶
type Auth ¶
type Auth struct { // 在整个gin.Context 上线文中的 Get 操作的key名,可以获得 AuthEntity ContextKey string // JwtHeaderKey jwt token 在HTTP请求中的header名 HeaderKey string // 默认为 false, 如果为 true , 将验证不通过后也会继续往下执行 Continue bool // jwt 加密 key Key interface{} AuthEntity AuthInterface // contains filtered or unexported fields }
Auth jwt认证对象
type AuthInterface ¶
type AuthInterface interface { database.Table GetTopic() interface{} // 返回唯一信息 FindByTopic(topic interface{}) AuthInterface // 根据唯一信息标识获取数据信息, 比如根据用户id获取用户信息,需要注意传入的数据类型 GetCheckData() string // 获取验证信息, jwt加密时, 改信息会一起进行加密, 解密时会解出来然后调用 Check 验证该信息的正确性, 如果是其他数据类型直接转string,比如是个结构体或者map, 直接转为json string Check(ctx *gin.Context, checkData string) bool // 验证信息 ExpiredAt() int64 // 返回过期时间,时间戳 }
AuthInterface 参与 jwt 数据表结构体需要实现这些接口
type CSRFToken ¶
type CSRFToken struct { Domain string `mapstructure:"domain"` Length int `mapstructure:"length"` SessionKey string `mapstructure:"session_key"` Duration string `mapstructure:"duration"` Path string `mapstructure:"path"` Secure bool `mapstructure:"secure"` HTTPOnly bool `mapstructure:"http_only"` }
CSRFToken csrf token
Click to show internal directories.
Click to hide internal directories.