token

package
v0.0.0-...-f99db60 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package token 提供JSON Web Token认证能力

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidToken = errors.New("invalid token")
	ErrExpiredToken = errors.New("expired token")
)

Functions

This section is empty.

Types

type Manager

type Manager interface {
	Create(userName string, duration time.Duration) (string, error)
	Verify(token string) (*Payload, error)
}

Manager token管理接口

type Payload

type Payload struct {
	ID        uuid.UUID `json:"id,omitempty"`
	UserName  string    `json:"user_name,omitempty"`
	IssuedAt  time.Time `json:"issued_at,omitempty"`
	ExpiredAt time.Time `json:"expired_at,omitempty"`
}

Payload token载荷信息

func NewPayload

func NewPayload(userName string, duration time.Duration) (*Payload, error)

NewPayload 工厂方法

func (*Payload) GetAudience

func (p *Payload) GetAudience() (jwt.ClaimStrings, error)

func (*Payload) GetExpirationTime

func (p *Payload) GetExpirationTime() (*jwt.NumericDate, error)

func (*Payload) GetIssuedAt

func (p *Payload) GetIssuedAt() (*jwt.NumericDate, error)

func (*Payload) GetIssuer

func (p *Payload) GetIssuer() (string, error)

func (*Payload) GetNotBefore

func (p *Payload) GetNotBefore() (*jwt.NumericDate, error)

func (*Payload) GetSubject

func (p *Payload) GetSubject() (string, error)

func (*Payload) Valid

func (p *Payload) Valid() error

Valid 自定义校验方法

Directories

Path Synopsis
Package jwt 提供JSON Web Token实现
Package jwt 提供JSON Web Token实现
Package paseto 提供Paseto Token实现
Package paseto 提供Paseto Token实现

Jump to

Keyboard shortcuts

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