token

package
v0.0.0-...-400441b Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Jwt

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

Jwt is a JSON Web Token implementation.

func (*Jwt) Create

func (j *Jwt) Create(userID uint, isAdmin bool) (string, error)

Create creates a new token for a specific user id, role, and duration.

func (*Jwt) Verify

func (j *Jwt) Verify(token string) (*Payload, error)

Verify checks if the token is valid or not

type Payload

type Payload struct {
	ID        uuid.UUID `json:"id"`
	UserID    uint      `json:"user_id"`
	IsAdmin   bool      `json:"is_admin"`
	IsUsedAt  time.Time `json:"isused_at"`
	ExpiredAt time.Time `json:"expired_at"`
}

Payload contains the payload data of the token

func NewPayload

func NewPayload(userID uint, isAdmin bool, duration time.Duration) (*Payload, error)

NewPayload creates a new token payload with a specific user id, role, and duration

func (*Payload) Valid

func (payload *Payload) Valid() error

Valid checks if the token payload is valid or not

type Token

type Token interface {
	// Create creates a new token for a specific user id, role, and duration
	Create(userID uint, isAdmin bool) (string, error)
	// Verify checks if the token is valid or not
	Verify(token string) (*Payload, error)
}

Token is an interface for token implementations

func New

func New(tokenCfg *config.Token) (Token, error)

New creates a new token instance based on the given token type

Jump to

Keyboard shortcuts

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