jwt

package
v1.0.1003 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2023 License: Apache-2.0 Imports: 7 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 DefaultSignerList = map[string]SignerMethod{

	"HS256": signer.SignerHS256,
	"HS384": signer.SignerHS384,
	"HS512": signer.SignerHS512,

	"RS256": signer.SignerRS256,
	"RS384": signer.SignerRS384,
	"RS512": signer.SignerRS512,

	"PS256": signer.SignerPS256,
	"PS384": signer.SignerPS384,
	"PS512": signer.SignerPS512,

	"ES256": signer.SignerES256,
	"ES384": signer.SignerES384,
	"ES512": signer.SignerES512,

	"EdDSA": signer.SignerEdDSA,

	"GmSM2": signer.SignerGmSM2,
}

验证方式列表

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, signer 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 HeaderMap

type HeaderMap = map[string]any

jwt 头数据

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 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
var DefaultSigner *Signer

默认

func NewSigner added in v1.0.1003

func NewSigner() *Signer

*

  • 签名

func (*Signer) AddSigner added in v1.0.1003

func (this *Signer) AddSigner(name string, signer 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(config.SignerConfig) interfaces.Signer

签名方法

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