token

package
v0.0.0-...-11c3768 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 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")
)

Functions

This section is empty.

Types

type Generator

type Generator interface {
	//CreateToken creates a new token for a specific username and duration
	CreateToken(username string, userID uuid.UUID, duration time.Duration) (string, *Payload, error)

	//VerifyToken checks if the token is valid or not
	VerifyToken(token string) (*Payload, error)
}

Generator is an interface for managing tokens

func NewJWTGenerator

func NewJWTGenerator(secretKey string) (Generator, error)

NewJWTGenerator creates a new JWT Token Generator object

func NewPasetoGenerator

func NewPasetoGenerator(symmetricKey string) (Generator, error)

NewPasetoGenerator creates a new PasetoGenerator object

type JWTGenerator

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

JWTGenerator is a JSON Web Token maker

func (*JWTGenerator) CreateToken

func (maker *JWTGenerator) CreateToken(username string, userID uuid.UUID, duration time.Duration) (string, *Payload, error)

CreateToken creates a new token for a specific username and duration

func (*JWTGenerator) VerifyToken

func (maker *JWTGenerator) VerifyToken(token string) (*Payload, error)

VerifyToken checks if the token is valid or not

type PasetoGenerator

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

PasetoGenerator is a PASETO Token maker

func (*PasetoGenerator) CreateToken

func (maker *PasetoGenerator) CreateToken(username string, userID uuid.UUID, duration time.Duration) (string, *Payload, error)

CreateToken creates a new token for a specific username and duration

func (*PasetoGenerator) VerifyToken

func (maker *PasetoGenerator) VerifyToken(token string) (*Payload, error)

VerifyToken checks if the token is valid or not

type Payload

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

Payload contains the payload data of a token

func NewPayload

func NewPayload(username string, userID uuid.UUID, duration time.Duration) (*Payload, error)

func (*Payload) Valid

func (payload *Payload) Valid() error

Valid checks if the payload token is valid

Jump to

Keyboard shortcuts

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