token

package
v0.0.0-...-d59b6e5 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Errors returned from ValidateToken method.

Functions

This section is empty.

Types

type Generator

type Generator interface {
	// GenerateToken creates a new token for the specified user.
	GenerateToken(userID int64, duration time.Duration) (string, *Payload, error)

	// ValidateToken validates if the token is proper.
	ValidateToken(token string) (*Payload, error)
}

Generator is a token management interface.

func NewJWTGenerator

func NewJWTGenerator(secretKey string) (Generator, error)

NewJWTGenerator creates a new JWT Generator.

func NewPasetoGenerator

func NewPasetoGenerator(symmetricKey string) (Generator, error)

NewJWTGenerator creates a new PASETO Generator.

type JWTGenerator

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

JWTGenerator struct represents a JSON Web Token generator.

func (*JWTGenerator) GenerateToken

func (g *JWTGenerator) GenerateToken(userID int64, duration time.Duration) (string, *Payload, error)

GenerateToken creates a new token for the specified user.

func (*JWTGenerator) ValidateToken

func (g *JWTGenerator) ValidateToken(token string) (*Payload, error)

ValidateToken validates if the token is proper.

type PasetoGenerator

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

PasetoGenerator struct represents a PASETO token generator.

func (*PasetoGenerator) GenerateToken

func (g *PasetoGenerator) GenerateToken(userID int64, duration time.Duration) (string, *Payload, error)

GenerateToken creates a new token for the specified user.

func (*PasetoGenerator) ValidateToken

func (g *PasetoGenerator) ValidateToken(token string) (*Payload, error)

ValidateToken validates if the token is proper.

type Payload

type Payload struct {
	ID        uuid.UUID `json:"id"`
	UserID    int64     `json:"user_id"`
	IssuedAt  time.Time `json:"issued_at"`
	ExpiredAt time.Time `json:"expired_at"`
}

Payload is the token's payload data.

func NewPayload

func NewPayload(userID int64, duration time.Duration) (*Payload, error)

NewPayload creates a new token payload for a user.

func (*Payload) Valid

func (p *Payload) Valid() error

Valid checks if the token is valid or not.

Jump to

Keyboard shortcuts

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