jwtx

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Overview

Package jwtx 提供与传输无关的 JWT 签发和解析, 供 server 鉴权中间件和应用侧共用同一套语义。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Codec

type Codec struct {
	Signer
	Parser
}

Codec 同时提供签发和解析能力,对应同一算法和密钥。

func Ed25519

func Ed25519(privateKeyPEM string) (Codec, error)

Ed25519 从 PEM 编码的 PKCS#8 私钥构造签发和解析 EdDSA token 的 Codec, 解析侧使用私钥派生的公钥。

func HS256

func HS256(secret string) Codec

HS256 返回以对称密钥签发和解析 HS256 token 的 Codec。

type Parser

type Parser struct {
	KeyFunc      jwt.Keyfunc
	ValidMethods []string
}

Parser 按算法白名单和密钥函数解析并校验 token。

func (Parser) Parse

func (p Parser) Parse(token string, claims jwt.Claims) error

Parse 解析 token 并把结果解码到 claims;签名、算法和有效期校验失败均返回错误。

type Signer

type Signer struct {
	Method jwt.SigningMethod
	Key    any
}

Signer 以指定算法和密钥签发 token。

func (Signer) Sign

func (s Signer) Sign(claims jwt.Claims) (string, error)

Sign 签发指定 Claims 的 token。

Jump to

Keyboard shortcuts

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