gojwt

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conf

type Conf struct {
	Secret string `yaml:"secret"` // 签名密钥
	Header string `yaml:"header"` // 传token时http head的名称
	TTL    uint   `yaml:"ttl"`    // 有效时间,单位:秒
	Issuer string `yaml:"issuer"` // 颁发者,一般指系统名
}

type JwtToken

type JwtToken struct {
	UID           string `json:"uid"`           // 所有者ID
	Role          string `json:"role"`          // 角色
	Token         string `json:"token"`         // token
	EffectiveTime uint   `json:"effectiveTime"` // 有效时间,单位:秒
}

JwtToken jwt的token

func CreateToken

func CreateToken(uid, role string, cfg Conf) (*JwtToken, error)

CreateToken 创建jwt token

func (JwtToken) JSON

func (t JwtToken) JSON() string

type RoleClaims

type RoleClaims struct {
	Role string
	jwt.StandardClaims
}

RoleClaims 带角色的claims

func ParseToken

func ParseToken(token, secret string) (*RoleClaims, error)

ParseToken 解析token

Jump to

Keyboard shortcuts

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