jwt

package
v1.0.1006 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: Apache-2.0 Imports: 5 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DecodeSegment = jwt.DecodeSegment

DecodeSegment(seg string) ([]byte, error)

View Source
var EncodeSegment = jwt.EncodeSegment

EncodeSegment(seg []byte) string

View Source
var GetSigningMethod = jwt.GetSigningMethod

获取注册的方法 GetSigningMethod(alg string) (method SigningMethod)

View Source
var NewJWT = jwt.New

New(method SigningMethod) *Token

View Source
var NewWithClaims = jwt.NewWithClaims

NewWithClaims(method SigningMethod, claims Claims) *Token

View Source
var Parse = jwt.Parse

Parse(tokenString string, keyFunc Keyfunc, options ...ParserOption) (*Token, error)

View Source
var ParseWithClaims = jwt.ParseWithClaims

ParseWithClaims(tokenString string, claims Claims, keyFunc Keyfunc, options ...ParserOption) (*Token, error)

View Source
var RegisterSigningMethod = jwt.RegisterSigningMethod

注册签名方法 RegisterSigningMethod(alg string, f func() SigningMethod)

View Source
var TimeFunc = jwt.TimeFunc

TimeFunc = time.Now

Functions

func AddSigner added in v1.0.1003

func AddSigner(name string, method SignerMethod)

添加签名

func DeleteSigner added in v1.0.1003

func DeleteSigner(name string)

判断签名

func GetAllSigner added in v1.0.1003

func GetAllSigner() map[string]SignerMethod

获取全部签名

func HasSigner added in v1.0.1003

func HasSigner(name string) bool

判断签名

Types

type ClaimMap

type ClaimMap = map[string]any

jwt 载荷

type ClaimStrings

type ClaimStrings = jwt.ClaimStrings

ClaimStrings

type Claims

type Claims = jwt.Claims

载荷

type Config added in v1.0.1005

type Config struct {
	// contains filtered or unexported fields
}

配置信息

func NewConfig added in v1.0.1005

func NewConfig(
	secret string,
	privateKey []byte,
	publicKey []byte,
	privateKeyPassword string,
) Config

构造函数

func (Config) PrivateKey added in v1.0.1005

func (this Config) PrivateKey() []byte

func (Config) PrivateKeyPassword added in v1.0.1005

func (this Config) PrivateKeyPassword() string

func (Config) PublicKey added in v1.0.1005

func (this Config) PublicKey() []byte

func (Config) Secret added in v1.0.1005

func (this Config) Secret() string

type ECDSA added in v1.0.1005

type ECDSA struct {
	// 配置
	Config IConfig

	// 签名
	SigningMethod jwt.SigningMethod
}

*

  • ECDSA *
  • @create 2023-2-5
  • @author deatil

func SignerES256 added in v1.0.1005

func SignerES256(conf IConfig) ECDSA

SignerES256

func SignerES384 added in v1.0.1005

func SignerES384(conf IConfig) ECDSA

SignerES384

func SignerES512 added in v1.0.1005

func SignerES512(conf IConfig) ECDSA

SignerES512

func (ECDSA) GetSignSecrect added in v1.0.1005

func (this ECDSA) GetSignSecrect() (secret any, err error)

签名密钥

func (ECDSA) GetSigner added in v1.0.1005

func (this ECDSA) GetSigner() jwt.SigningMethod

获取签名

func (ECDSA) GetVerifySecrect added in v1.0.1005

func (this ECDSA) GetVerifySecrect() (secret any, err error)

验证密钥

type EdDSA added in v1.0.1005

type EdDSA struct {
	// 配置
	Config IConfig

	// 签名
	SigningMethod jwt.SigningMethod
}

*

  • EdDSA *
  • @create 2023-2-5
  • @author deatil

func SignerEdDSA added in v1.0.1005

func SignerEdDSA(conf IConfig) EdDSA

SignerEdDSA

func (EdDSA) GetSignSecrect added in v1.0.1005

func (this EdDSA) GetSignSecrect() (secret any, err error)

签名密钥

func (EdDSA) GetSigner added in v1.0.1005

func (this EdDSA) GetSigner() jwt.SigningMethod

获取签名

func (EdDSA) GetVerifySecrect added in v1.0.1005

func (this EdDSA) GetVerifySecrect() (secret any, err error)

验证密钥

type GmSM2 added in v1.0.1005

type GmSM2 struct {
	// 配置
	Config IConfig

	// 签名
	SigningMethod jwt.SigningMethod
}

*

  • GmSM2 *
  • @create 2023-2-5
  • @author deatil

func SignerGmSM2 added in v1.0.1005

func SignerGmSM2(conf IConfig) GmSM2

SignerGmSM2

func (GmSM2) GetSignSecrect added in v1.0.1005

func (this GmSM2) GetSignSecrect() (secret any, err error)

签名密钥

func (GmSM2) GetSigner added in v1.0.1005

func (this GmSM2) GetSigner() jwt.SigningMethod

获取签名

func (GmSM2) GetVerifySecrect added in v1.0.1005

func (this GmSM2) GetVerifySecrect() (secret any, err error)

验证密钥

type HeaderMap

type HeaderMap = map[string]any

jwt 头数据

type Hmac added in v1.0.1005

type Hmac struct {
	// 配置
	Config IConfig

	// 签名
	SigningMethod jwt.SigningMethod
}

*

  • Hmac *
  • @create 2023-2-5
  • @author deatil

func SignerHS256 added in v1.0.1005

func SignerHS256(conf IConfig) Hmac

SignerHS256

func SignerHS384 added in v1.0.1005

func SignerHS384(conf IConfig) Hmac

SignerHS384

func SignerHS512 added in v1.0.1005

func SignerHS512(conf IConfig) Hmac

SignerHS512

func (Hmac) GetSignSecrect added in v1.0.1005

func (this Hmac) GetSignSecrect() (secret any, err error)

签名密钥

func (Hmac) GetSigner added in v1.0.1005

func (this Hmac) GetSigner() jwt.SigningMethod

获取签名

func (Hmac) GetVerifySecrect added in v1.0.1005

func (this Hmac) GetVerifySecrect() (secret any, err error)

验证密钥

type IConfig added in v1.0.1005

type IConfig interface {
	// 秘钥
	Secret() string

	// 私钥
	PrivateKey() []byte

	// 公钥
	PublicKey() []byte

	// 私钥密码
	PrivateKeyPassword() string
}

*

  • 配置接口 *
  • @create 2023-4-5
  • @author deatil

type ISigner added in v1.0.1005

type ISigner interface {
	// 获取签名
	GetSigner() jwt.SigningMethod

	// 签名密钥
	GetSignSecrect() (any, error)

	// 验证密钥
	GetVerifySecrect() (any, error)
}

*

  • 签名数据接口 *
  • @create 2023-2-5
  • @author deatil

type JWT

type JWT struct {
	// 头数据
	Headers HeaderMap

	// 载荷
	Claims ClaimMap

	// 签名方法
	SigningMethod string

	// 秘钥
	Secret string

	// 私钥
	PrivateKey []byte

	// 公钥
	PublicKey []byte

	// 私钥密码
	PrivateKeyPassword string
}

*

  • JWT *
  • @create 2021-9-15
  • @author deatil

func New

func New(opts ...Option) *JWT

JWT

func (*JWT) GetClaimsFromToken

func (this *JWT) GetClaimsFromToken(token *Token) (MapClaims, error)

从 token 获取解析后的[载荷]数据

func (*JWT) GetHeadersFromToken

func (this *JWT) GetHeadersFromToken(token *Token) (ParsedHeaderMap, error)

从 token 获取解析后的[Header]数据

func (*JWT) MakeToken

func (this *JWT) MakeToken() (token string, err error)

生成token

func (*JWT) ParseToken

func (this *JWT) ParseToken(strToken string) (*Token, error)

解析 token

func (*JWT) Validate

func (this *JWT) Validate(token *Token) (bool, error)

token 过期检测

func (*JWT) Verify

func (this *JWT) Verify(token *Token) (bool, error)

验证 token 是否有效

func (*JWT) WithAud

func (this *JWT) WithAud(aud string) *JWT

(Audience) 接收方

func (*JWT) WithClaim

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

自定义载荷

func (*JWT) WithExp

func (this *JWT) WithExp(exp int64) *JWT

(Expiration Time) 过期时间,unix时间戳

func (*JWT) WithHeader

func (this *JWT) WithHeader(key string, value any) *JWT

自定义 Header

func (*JWT) WithIat

func (this *JWT) WithIat(iat int64) *JWT

(Issued At) 签发时间,unix时间戳

func (*JWT) WithIss

func (this *JWT) WithIss(iss string) *JWT

(Issuer) 签发者

func (*JWT) WithJti

func (this *JWT) WithJti(jti string) *JWT

(JWT ID) 唯一ID

func (*JWT) WithNbf

func (this *JWT) WithNbf(nbf int64) *JWT

(Not Before) 不要早于这个时间

func (*JWT) WithOption added in v1.0.1003

func (this *JWT) WithOption(opts ...Option) *JWT

设置

func (*JWT) WithPrivateKey

func (this *JWT) WithPrivateKey(privateKey []byte) *JWT

私钥

func (*JWT) WithPrivateKeyPassword

func (this *JWT) WithPrivateKeyPassword(password string) *JWT

私钥密码

func (*JWT) WithPublicKey

func (this *JWT) WithPublicKey(publicKey []byte) *JWT

公钥

func (*JWT) WithSecret

func (this *JWT) WithSecret(secret string) *JWT

密码

func (*JWT) WithSigningMethod

func (this *JWT) WithSigningMethod(method string) *JWT

验证方式

func (*JWT) WithSub

func (this *JWT) WithSub(sub string) *JWT

(Subject) 主题

type Keyfunc

type Keyfunc = jwt.Keyfunc

Keyfunc

type MapClaims

type MapClaims = jwt.MapClaims

载荷 map

type NumericDate

type NumericDate = jwt.NumericDate

NumericDate

type Option added in v1.0.1003

type Option func(*JWT)

func WithAud added in v1.0.1003

func WithAud(aud string) Option

(Audience) 接收方

func WithClaim added in v1.0.1003

func WithClaim(key string, value any) Option

自定义载荷

func WithExp added in v1.0.1003

func WithExp(exp int64) Option

(Expiration Time) 过期时间,unix时间戳

func WithHeader added in v1.0.1003

func WithHeader(key string, value any) Option

自定义 Header

func WithIat added in v1.0.1003

func WithIat(iat int64) Option

(Issued At) 签发时间,unix时间戳

func WithIss added in v1.0.1003

func WithIss(iss string) Option

(Issuer) 签发者

func WithJti added in v1.0.1003

func WithJti(jti string) Option

(JWT ID) 唯一ID

func WithNbf added in v1.0.1003

func WithNbf(nbf int64) Option

(Not Before) 不要早于这个时间

func WithPrivateKey added in v1.0.1003

func WithPrivateKey(privateKey []byte) Option

私钥

func WithPrivateKeyPassword added in v1.0.1003

func WithPrivateKeyPassword(password string) Option

私钥密码

func WithPublicKey added in v1.0.1003

func WithPublicKey(publicKey []byte) Option

公钥

func WithSecret added in v1.0.1003

func WithSecret(secret string) Option

密码

func WithSigningMethod added in v1.0.1003

func WithSigningMethod(method string) Option

验证方式

func WithSub added in v1.0.1003

func WithSub(sub string) Option

(Subject) 主题

type ParsedHeaderMap

type ParsedHeaderMap = map[string]any

jwt 解析后的头数据 map

type Parser

type Parser = jwt.Parser

解析

type RSA added in v1.0.1005

type RSA struct {
	// 配置
	Config IConfig

	// 签名
	SigningMethod jwt.SigningMethod
}

*

  • RSA *
  • @create 2023-2-5
  • @author deatil

func SignerPS256 added in v1.0.1005

func SignerPS256(conf IConfig) RSA

SignerPS256

func SignerPS384 added in v1.0.1005

func SignerPS384(conf IConfig) RSA

SignerPS384

func SignerPS512 added in v1.0.1005

func SignerPS512(conf IConfig) RSA

SignerPS512

func SignerRS256 added in v1.0.1005

func SignerRS256(conf IConfig) RSA

SignerRS256

func SignerRS384 added in v1.0.1005

func SignerRS384(conf IConfig) RSA

SignerRS384

func SignerRS512 added in v1.0.1005

func SignerRS512(conf IConfig) RSA

SignerRS512

func (RSA) GetSignSecrect added in v1.0.1005

func (this RSA) GetSignSecrect() (secret any, err error)

签名密钥

func (RSA) GetSigner added in v1.0.1005

func (this RSA) GetSigner() jwt.SigningMethod

获取签名

func (RSA) GetVerifySecrect added in v1.0.1005

func (this RSA) GetVerifySecrect() (secret any, err error)

验证密钥

type RegisteredClaims

type RegisteredClaims = jwt.RegisteredClaims

已注册载荷

type Signer added in v1.0.1003

type Signer struct {
	// contains filtered or unexported fields
}

*

  • 签名 *
  • @create 2023-2-5
  • @author deatil

func NewSigner added in v1.0.1003

func NewSigner() *Signer

*

  • 签名

func (*Signer) AddSigner added in v1.0.1003

func (this *Signer) AddSigner(name string, method SignerMethod)

注册

func (*Signer) DeleteSigner added in v1.0.1003

func (this *Signer) DeleteSigner(name string)

删除

func (*Signer) GetAllSigner added in v1.0.1003

func (this *Signer) GetAllSigner() map[string]SignerMethod

获取全部

func (*Signer) GetSigner added in v1.0.1003

func (this *Signer) GetSigner(name string) SignerMethod

获取

func (*Signer) HasSigner added in v1.0.1003

func (this *Signer) HasSigner(name string) bool

判断

type SignerMethod added in v1.0.1003

type SignerMethod = func(IConfig) ISigner

签名方法

func GetSigner added in v1.0.1003

func GetSigner(name string) SignerMethod

获取签名

type SigningMethod

type SigningMethod = jwt.SigningMethod

签名方法

type StandardClaims

type StandardClaims = jwt.StandardClaims

StandardClaims

type Token

type Token = jwt.Token

Token

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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