jwt

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2019 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JWT          = "JWT"
	SHA256       = "SHA256"
	QUARTER_HOUR = int64(900000)
	HALF_HOUR    = int64(3600000)
	TWO_WEEK     = int64(1209600000)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Authorization

type Authorization struct {
	AccessTime   int64  `json:"accessTime"`   // 授权时间
	AccessToken  string `json:"accessToken"`  // 授权Token
	RefreshToken string `json:"refreshToken"` // 续期Token
	Signature    string `json:"signature"`    // Token签名
}
type Header struct {
	Nod int64  `json:"nod"` // 认证节点
	Typ string `json:"typ"` // 认证类型
	Alg string `json:"alg"` // 算法类型,默认SHA256
}

type Payload

type Payload struct {
	Sub string            `json:"sub"` // 用户主体
	Aud string            `json:"aud"` // 接收token主体
	Iss string            `json:"iss"` // 签发token主体
	Iat int64             `json:"iat"` // 授权token时间
	Exp int64             `json:"exp"` // 授权token过期时间
	Rxp int64             `json:"rxp"` // 续期token过期时间
	Nbf int64             `json:"nbf"` // 定义在什么时间之前,该token都是不可用的
	Jti string            `json:"jti"` // 唯一身份标识,主要用来作为一次性token,从而回避重放攻击
	Ext map[string]string `json:"ext"` // 扩展信息
}

type Subject

type Subject struct {
	Header  *Header
	Payload *Payload
}

func (*Subject) Generate

func (self *Subject) Generate(secret string, refresh ...bool) (*Authorization, error)

生成Token

func (*Subject) Refresh

func (self *Subject) Refresh(accessToken, refreshToken, secret string, accessTime int64, interval ...int64) (*Authorization, error)

续期Token

func (*Subject) Valid

func (self *Subject) Valid(accessToken, secret string, refresh bool, aud ...string) error

校验Token

Jump to

Keyboard shortcuts

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