jwtutil

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractJWTFromRequest

func ExtractJWTFromRequest(r *http.Request) (string, error)

ExtractJWTFromRequest 从请求中提取JWT

func GenerateGenericJWT

func GenerateGenericJWT[T any](payload T, secretKey []byte, signingMethod jwt.SigningMethod) (string, error)

GenerateGenericJWT 生成 JWT

func GenerateJWT

func GenerateJWT(mapClaims jwt.MapClaims, secretKey []byte, signingMethod jwt.SigningMethod) (string, error)

GenerateJWT 生成 JWT

func GenerateJWTWithHeader

func GenerateJWTWithHeader(payload jwt.MapClaims, secretKey []byte, signingMethod jwt.SigningMethod, customHeader map[string]interface{}) (string, error)

GenerateJWTWithHeader 生成带自定义头部的JWT

func GenerateShortLivedJWT

func GenerateShortLivedJWT(payload jwt.MapClaims, secretKey []byte, signingMethod jwt.SigningMethod, duration time.Duration) (string, error)

GenerateShortLivedJWT 生成短期有效的JWT

func GetJWTClaims

func GetJWTClaims(tokenString string) (map[string]interface{}, error)

func GetJWTHeader

func GetJWTHeader(tokenString string) (map[string]interface{}, error)

GetJWTHeader 获取JWT头部

func GetJWTIssuedAt

func GetJWTIssuedAt(tokenString string) (*time.Time, error)

GetJWTIssuedAt 获取JWT签发时间

func IsJWTExpired

func IsJWTExpired(tokenString string) (bool, error)

IsJWTExpired 检查JWT是否过期

func NewJWTId

func NewJWTId() string

NewJWTId 生成一个唯一的 JWT ID (jti)

func NewRefreshToken

func NewRefreshToken() (string, error)

NewRefreshToken 生成一个安全的随机刷新令牌

func ParseJWTClaimsToStruct

func ParseJWTClaimsToStruct[T any](tokenString string) (*T, error)

ParseJWTClaimsToStruct 解析 JWT 的负载部分,不验证签名,仅解析。

func ParseJWTPayload

func ParseJWTPayload(tokenString string) (jwt.MapClaims, error)

ParseJWTPayload 使用 github.com/golang-jwt/jwt/v5 从 JWT 中解析出 payload

func RefreshJWT

func RefreshJWT(tokenString string, secretKey []byte, newExpiration time.Time) (string, error)

RefreshJWT 刷新JWT

func ToMapClaims

func ToMapClaims[T any](payload T) (jwt.MapClaims, error)

ToMapClaims 将泛型 payload 转换为 jwt.MapClaims

func ValidateJWTAlgorithm

func ValidateJWTAlgorithm(tokenString string, expectedAlgorithm string) (bool, error)

ValidateJWTAlgorithm 验证JWT算法

func ValidateJWTAudience

func ValidateJWTAudience(tokenString string, expectedAudience string) (bool, error)

ValidateJWTAudience 验证JWT受众

func ValidateJWTIssuer

func ValidateJWTIssuer(tokenString string, expectedIssuer string) (bool, error)

ValidateJWTIssuer 验证JWT发行者

func VerifyJWT

func VerifyJWT(tokenString string, secretKey []byte) (jwt.MapClaims, error)

VerifyJWT 验证 JWT 的签名

Types

This section is empty.

Jump to

Keyboard shortcuts

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