Documentation
¶
Index ¶
- Constants
- func DecodeSegment(seg string) ([]byte, error)
- func EncodeSegment(seg []byte) string
- func SplicingSegment(segment ...string) string
- func Split2Segment(v string) []string
- type Claim
- func WithCustom(key string, value interface{}) Claim
- func WithDuration(duration time.Duration) Claim
- func WithExpire(expire time.Time) Claim
- func WithExternal(external External) Claim
- func WithIssuer(issuer string) Claim
- func WithOwner(owner string) Claim
- func WithPurpose(purpose string) Claim
- func WithRecipient(recipient string) Claim
- func WithTime(time time.Time) Claim
- type External
- type Payload
- type Token
- func (token *Token) Claim(key string, value interface{}) *Token
- func (token *Token) Expired() bool
- func (token *Token) Refresh(secret string) (string, error)
- func (token *Token) SetDuration(duration time.Duration) *Token
- func (token *Token) SetExpire(expire time.Time) *Token
- func (token *Token) SetExternal(external External) *Token
- func (token *Token) SetIssuer(issuer string) *Token
- func (token *Token) SetOwner(owner string) *Token
- func (token *Token) SetPurpose(purpose string) *Token
- func (token *Token) SetRecipient(recipient string) *Token
- func (token *Token) Sign(secret string) (string, error)
- func (token *Token) String(secret string) (string, error)
- func (token *Token) Valid(secret string) error
Constants ¶
View Source
const ( RecipientBrowser = "browser" RecipientAndroid = "android" RecipientIOS = "ios" RecipientWechat = "wechat mini program" )
Variables ¶
This section is empty.
Functions ¶
func DecodeSegment ¶
DecodeSegment decode JWT specific base64url encoding with padding stripped
func EncodeSegment ¶
EncodeSegment encode JWT specific base64url encoding with padding stripped
func SplicingSegment ¶
func Split2Segment ¶
Types ¶
type Claim ¶
type Claim func(*Payload)
func WithCustom ¶
func WithDuration ¶
func WithExpire ¶
func WithExternal ¶
func WithIssuer ¶
func WithPurpose ¶
func WithRecipient ¶
type Payload ¶
type Payload struct {
// 签发者
Issuer string `json:"issuer,omitempty"`
// 令牌所有者,存放ID等标识
Owner string `json:"owner,omitempty"`
// 用途,默认值authentication表示用于登录认证
Purpose string `json:"purpose,omitempty"`
// 接受方,表示申请该令牌的设备来源,如浏览器、Android等
Recipient string `json:"recipient,omitempty"`
// 令牌签发时间
Time time.Time `json:"time"`
// 过期时间, expire = time + duration
Expire time.Time `json:"expire,omitempty"`
// 令牌持续时间,即生命周期,0则表示没有设置过期时间
Duration time.Duration `json:"duration,omitempty"`
// 其他扩展的自定义参数
External External `json:"external,omitempty"`
}
type Token ¶
type Token struct {
Raw string
Header map[string]string
Payload *Payload
Signature string
Algorithm alg.Algorithm
}
func (*Token) Refresh ¶
Refresh Reset the expiration time based on the current time according to the duration of the token 在当前时间基础上根据token的持续时间重置过期时间
func (*Token) SetDuration ¶
SetDuration Set the token validity time, the expiration time will be reset based on the current time. 设置token有效时间, 将在当前时间基础上重置过期时间
func (*Token) SetExternal ¶
func (*Token) SetPurpose ¶
func (*Token) SetRecipient ¶
Click to show internal directories.
Click to hide internal directories.