token

package
v0.0.0-...-94fa1f8 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

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 JWTToken

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

func (JWTToken) CreateToken

func (t JWTToken) CreateToken(data string, duration time.Duration) (string, error)

func (JWTToken) ValidateToken

func (t JWTToken) ValidateToken(token string) (*Payload, error)

type PasetoToken

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

func (PasetoToken) CreateToken

func (t PasetoToken) CreateToken(data string, duration time.Duration) (string, error)

func (PasetoToken) ValidateToken

func (t PasetoToken) ValidateToken(token string) (*Payload, error)

type Payload

type Payload struct {
	ID        uuid.UUID        `json:"id"`
	Data      string           `json:"data"`
	ExpiredAt *jwt.NumericDate `json:"expired_at"`
}

func NewPayload

func NewPayload(data string, time time.Time) *Payload

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)

type Token

type Token interface {
	CreateToken(string, time.Duration) (string, error)
	ValidateToken(string) (*Payload, error)
}

func NewJWTToken

func NewJWTToken(secretKey string, method jwt.SigningMethod) Token

func NewPasetoToken

func NewPasetoToken(secretKey string) Token

Jump to

Keyboard shortcuts

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