jwt

package
v0.25.3 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JWT

type JWT struct {
	ModuleName       string                 `mapstructure:"module-name" yaml:"module-name" json:"moduleName"`                                      // 模块名称
	SigningKey       string                 `mapstructure:"signing-key" yaml:"signing-key" json:"signingKey"      validate:"required"`             // jwt 签名
	ExpiresTime      int64                  `mapstructure:"expires-time" yaml:"expires-time" json:"expiresTime"     validate:"required,min=1"`     // 过期时间(单位:秒)
	BufferTime       int64                  `mapstructure:"buffer-time" yaml:"buffer-time" json:"bufferTime"      validate:"required,min=0"`       // 缓冲时间(单位:秒)
	UseMultipoint    bool                   `mapstructure:"use-multipoint" yaml:"use-multipoint" json:"useMultipoint"`                             // 多地登录拦截,true 表示拦截,false 表示不拦截
	Issuer           string                 `mapstructure:"issuer" yaml:"issuer" json:"issuer"`                                                    // JWT 发行者
	Audience         string                 `mapstructure:"audience" yaml:"audience" json:"audience"`                                              // JWT 接收者
	Algorithm        string                 `mapstructure:"algorithm" yaml:"algorithm" json:"algorithm"      validate:"required"`                  // 签名算法,例如 HMAC, RSA, etc.
	EnableRefresh    bool                   `mapstructure:"enable-refresh" yaml:"enable-refresh" json:"enableRefresh"`                             // 是否启用刷新 token
	RefreshTokenLife int64                  `mapstructure:"refresh-token-life" yaml:"refresh-token-life" json:"refreshTokenLife" validate:"min=1"` // 刷新 token 生命周期(单位:秒)
	Subject          string                 `mapstructure:"subject" yaml:"subject" json:"subject"`                                                 // JWT 主题
	CustomClaims     map[string]interface{} `mapstructure:"custom-claims" yaml:"custom-claims" json:"customClaims"`                                // 自定义声明
}

JWT 结构体用于配置 JSON Web Token 的相关参数

func Default

func Default() *JWT

Default 返回默认JWT配置的指针,支持链式调用

func DefaultJWT

func DefaultJWT() JWT

DefaultJWT 返回默认JWT配置

func NewJWT

func NewJWT(opt *JWT) *JWT

NewJWT 创建一个新的 JWT 实例

func (*JWT) Clone

func (j *JWT) Clone() internal.Configurable

Clone 返回 JWT 配置的副本

func (*JWT) Get

func (j *JWT) Get() interface{}

Get 返回 JWT 配置的所有字段

func (*JWT) Reload

func (j *JWT) Reload(data interface{})

Load 从另一个 JWT 实例重新加载配置

func (*JWT) Set

func (j *JWT) Set(data interface{})

Set 更新 JWT 配置的字段

func (*JWT) Validate

func (j *JWT) Validate() error

Validate 检查 JWT 配置的有效性

func (*JWT) WithAlgorithm

func (j *JWT) WithAlgorithm(algorithm string) *JWT

WithAlgorithm 设置签名算法

func (*JWT) WithAudience

func (j *JWT) WithAudience(audience string) *JWT

WithAudience 设置接收者

func (*JWT) WithBufferTime

func (j *JWT) WithBufferTime(bufferTime int64) *JWT

WithBufferTime 设置缓冲时间(单位:秒)

func (*JWT) WithCustomClaims

func (j *JWT) WithCustomClaims(customClaims map[string]interface{}) *JWT

WithCustomClaims 设置自定义声明

func (*JWT) WithEnableRefresh

func (j *JWT) WithEnableRefresh(enableRefresh bool) *JWT

WithEnableRefresh 设置是否启用刷新 token

func (*JWT) WithExpiresTime

func (j *JWT) WithExpiresTime(expiresTime int64) *JWT

WithExpiresTime 设置过期时间(单位:秒)

func (*JWT) WithIssuer

func (j *JWT) WithIssuer(issuer string) *JWT

WithIssuer 设置发行者

func (*JWT) WithModuleName

func (j *JWT) WithModuleName(moduleName string) *JWT

WithModuleName 设置模块名称

func (*JWT) WithRefreshTokenLife

func (j *JWT) WithRefreshTokenLife(refreshTokenLife int64) *JWT

WithRefreshTokenLife 设置刷新 token 生命周期(单位:秒)

func (*JWT) WithSigningKey

func (j *JWT) WithSigningKey(signingKey string) *JWT

WithSigningKey 设置签名密钥

func (*JWT) WithSubject

func (j *JWT) WithSubject(subject string) *JWT

WithSubject 设置主题

func (*JWT) WithUseMultipoint

func (j *JWT) WithUseMultipoint(useMultipoint bool) *JWT

WithUseMultipoint 设置是否启用多地登录拦截

Jump to

Keyboard shortcuts

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