jwt

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingJwtToken        = errors.New("JWT token is missing")
	ErrTokenInvalid           = errors.New("JWT token is invalid")
	ErrTokenExpired           = errors.New("JWT token is expired")
	ErrTokenParseFail         = errors.New("fail to parse JWT token")
	ErrUnSupportSigningMethod = errors.New("unsupported signing method")
)

Functions

This section is empty.

Types

type Claims

type Claims struct {
	Role string `json:"role"`
	jwt.RegisteredClaims
}

type Jwt

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

func NewJwt

func NewJwt(opts ...Option) *Jwt

func (*Jwt) Generate

func (j *Jwt) Generate(memberId, role string) (string, error)

func (*Jwt) Parse

func (j *Jwt) Parse(jwtToken string) (*Claims, error)

type Option

type Option interface {
	Apply(*Options)
}

func WithAudience

func WithAudience(audience []string) Option

func WithExpiresTime

func WithExpiresTime(expiresTime int64) Option

func WithIssuer

func WithIssuer(issuer string) Option

func WithSigningKey

func WithSigningKey(signingKey string) Option

func WithSigningMethod

func WithSigningMethod(signingMethod jwt.SigningMethod) Option

type Options

type Options struct {
	SigningMethod jwt.SigningMethod
	SigningKey    []byte        // 秘钥
	ExpiresTime   time.Duration // token有效时长(s)
	Issuer        string        // 用于标识JWT的发行者,可以是一个URI或者服务器的名称。
	Audience      []string      // aud用于标识JWT的预期接收者,可以是一个或多个实体。
}

Jump to

Keyboard shortcuts

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