jwt

package
v1.0.159 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JWT          = "JWT"
	HS256        = "HS256"
	SHA256       = "SHA256"
	MD5          = "MD5"
	AES          = "AES"
	RSA          = "RSA"
	FIVE_MINUTES = int64(300)
	TWO_WEEK     = int64(1209600)
)

Variables

This section is empty.

Functions

func GetTokenSecret

func GetTokenSecret(token, secret string) string

获取token的私钥

Types

type Header struct {
	Alg string `json:"alg"`
	Typ string `json:"typ"`
}

type JwtConfig

type JwtConfig struct {
	TokenKey string
	TokenAlg string
	TokenTyp string
	TokenExp int64
}

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过期时间
	Dev string `json:"dev"` // 设备类型,web/app
	Jti string `json:"jti"` // 唯一身份标识,主要用来作为一次性token,从而回避重放攻击
	Ext string `json:"ext"` // 扩展信息
}

type Subject

type Subject struct {
	Header  *Header
	Payload *Payload
	// contains filtered or unexported fields
}

func (*Subject) AddHeader

func (self *Subject) AddHeader(config JwtConfig) *Subject

func (*Subject) Aud

func (self *Subject) Aud(aud string) *Subject

func (*Subject) CheckReady added in v1.0.104

func (self *Subject) CheckReady() bool

func (*Subject) Create

func (self *Subject) Create(sub string) *Subject

func (*Subject) Dev

func (self *Subject) Dev(dev string) *Subject

func (*Subject) Expired

func (self *Subject) Expired(exp int64) *Subject

exp seconds

func (*Subject) Generate

func (self *Subject) Generate(config JwtConfig) string

func (*Subject) GetAud added in v1.0.104

func (self *Subject) GetAud() string

func (*Subject) GetDev added in v1.0.104

func (self *Subject) GetDev() string

func (*Subject) GetExp added in v1.0.104

func (self *Subject) GetExp() int64

func (*Subject) GetExt added in v1.0.104

func (self *Subject) GetExt() string

func (*Subject) GetIat added in v1.0.104

func (self *Subject) GetIat() int64

func (*Subject) GetIss added in v1.0.104

func (self *Subject) GetIss() string

func (*Subject) GetJti added in v1.0.104

func (self *Subject) GetJti() string

func (*Subject) GetRawBytes added in v1.0.105

func (self *Subject) GetRawBytes() []byte

func (*Subject) GetSub added in v1.0.104

func (self *Subject) GetSub() string

func (*Subject) GetTokenSecret

func (self *Subject) GetTokenSecret(token, secret string) string

func (*Subject) Iss

func (self *Subject) Iss(iss string) *Subject

func (*Subject) ResetPayloadBytes added in v1.0.111

func (self *Subject) ResetPayloadBytes(b []byte)

func (*Subject) ResetTokenBytes added in v1.0.111

func (self *Subject) ResetTokenBytes(b []byte)

func (*Subject) Signature

func (self *Subject) Signature(text, key string) string

func (*Subject) Verify

func (self *Subject) Verify(token, key string, decode bool) error

Jump to

Keyboard shortcuts

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