token

package
v0.0.0-...-8f6dbd5 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Maker

type Maker interface {
	// CreateToken creates a new token for a specific username and duration.
	// Returns token, payload and error
	CreateToken(username string, role string, duration time.Duration) (string, *Payload, error)
	// VerifyToken checks if the token is valid or not
	VerifyToken(token string) (*Payload, error)
}

Maker is an interface that creates and verifies tokens

func NewPasetoMaker

func NewPasetoMaker(symmetricKey string) (Maker, error)

type PasetoMaker

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

func (*PasetoMaker) CreateToken

func (m *PasetoMaker) CreateToken(username string, role string, duration time.Duration) (string, *Payload, error)

CreateToken creates a new paseto token for a specific username and duration

func (*PasetoMaker) VerifyToken

func (m *PasetoMaker) VerifyToken(token string) (*Payload, error)

type Payload

type Payload struct {
	// ID is the id of the token
	ID uuid.UUID `json:"id"`
	// Username is the username of the token user
	Username string `json:"username"`
	// Role is the role of the token user
	Role string `json:"role"`
	// IssuedAt is the time the token was issued
	IssuedAt time.Time `json:"issued_at"`
	// ExpiredAt is the time the token will expire
	ExpiredAt time.Time `json:"expired_at"`
}

Payload is the payload of the token

func NewPayload

func NewPayload(username string, role string, duration time.Duration) *Payload

NewPayload creates a new payload for the token

func (*Payload) Valid

func (p *Payload) Valid() error

Valid checks if the token is valid or not. If the token is invalid, it returns an error

Jump to

Keyboard shortcuts

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