token

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClaimMap

type ClaimMap = map[string]any

载荷

type ConfigMap

type ConfigMap = map[string]any

配置

type Token

type Token struct {

	// jwt
	JWT *jwt.JWT

	// 配置
	Config ConfigMap

	// 载荷
	Claims ClaimMap
	// contains filtered or unexported fields
}

*

  • 授权 *
  • @create 2021-6-19
  • @author deatil

func New

func New(j *jwt.JWT) *Token

授权结构体

func (*Token) Decode

func (this *Token) Decode(data string, passphrase string, iv string) string

解密

func (*Token) Encode

func (this *Token) Encode(data string, passphrase string, iv string) string

加密

func (*Token) FileExist

func (this *Token) FileExist(fp string) bool

文件判断

func (*Token) FormatPath

func (this *Token) FormatPath(file string) string

格式化文件路径

func (*Token) GetAccessExpiresIn

func (this *Token) GetAccessExpiresIn() int

*

  • 获取鉴权 token 过期时间

func (*Token) GetAccessTokenClaims

func (this *Token) GetAccessTokenClaims(token string, verify ...bool) (jwt.MapClaims, error)

*

  • 获取鉴权 token

func (*Token) GetAccessTokenData

func (this *Token) GetAccessTokenData(token string, key string, verify ...bool) string

*

  • 获取鉴权 token 所在 userid

func (*Token) GetConfig

func (this *Token) GetConfig(key string) any

*

  • 获取配置

func (*Token) GetDataFromTokenClaims

func (this *Token) GetDataFromTokenClaims(claims jwt.MapClaims, key string) string

*

  • 从 TokenClaims 获取数据

func (*Token) GetFromTokenClaims

func (this *Token) GetFromTokenClaims(claims jwt.MapClaims, key string) any

*

  • 从 Claims 获取数据

func (*Token) GetIntConfig

func (this *Token) GetIntConfig(key string, defVal int) int

*

  • 获取配置

func (*Token) GetRefreshExpiresIn

func (this *Token) GetRefreshExpiresIn() int

*

  • 获取刷新 token 过期时间

func (*Token) GetRefreshTokenClaims

func (this *Token) GetRefreshTokenClaims(token string, verify ...bool) (jwt.MapClaims, error)

*

  • 获取刷新 token

func (*Token) GetRefreshTokenData

func (this *Token) GetRefreshTokenData(token string, key string, verify ...bool) string

*

  • 获取刷新 token 所在 userid

func (*Token) GetStringConfig

func (this *Token) GetStringConfig(key string, defVal string) string

*

  • 获取配置

func (*Token) MakeAccessToken

func (this *Token) MakeAccessToken(claims map[string]string) (token string, err error)

*

  • 生成鉴权 token

func (*Token) MakeJWT

func (this *Token) MakeJWT() *jwt.JWT

*

  • 生成鉴权 token

func (*Token) MakeRefreshToken

func (this *Token) MakeRefreshToken(claims map[string]string) (token string, err error)

*

  • 生成刷新 token

func (*Token) MakeToken

func (this *Token) MakeToken(claims map[string]string) (token string, err error)

*

  • 生成 token

func (*Token) ReadDataFromFile

func (this *Token) ReadDataFromFile(file string) ([]byte, error)

从文件读取数据

func (*Token) SetConfig

func (this *Token) SetConfig(key string, value any) *Token

*

  • 设置配置

func (*Token) WithClaim

func (this *Token) WithClaim(key string, value any) *Token

设置自定义载荷

func (*Token) WithConfig

func (this *Token) WithConfig(configs ConfigMap) *Token

*

  • 批量设置配置

Jump to

Keyboard shortcuts

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