jwt

package
v1.0.82 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 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时间1
	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
}

func (*Subject) AddHeader

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

func (*Subject) Aud

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

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) GetTokenSecret

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

func (*Subject) Iss

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

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