token

package
v0.0.0-...-c7a98c3 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InvalidToken = errors.New("invalid token")
	ExpiredToken = errors.New("expired token")
)

Functions

func GenerateSymmetricKey

func GenerateSymmetricKey() string

Types

type JWTMaker

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

func (*JWTMaker) CreateToken

func (j *JWTMaker) CreateToken(username string, duration time.Duration) (string, *Payload, error)

CreateToken returns token, paylaod if creates token that specified username and duration success else error

func (*JWTMaker) VerifyToken

func (j *JWTMaker) VerifyToken(token string) (*Payload, error)

VerifyToken return the payload if the token is valid passed else error

type Maker

type Maker interface {
	CreateToken(username string, duration time.Duration) (string, *Payload, error)
	VerifyToken(token string) (*Payload, error)
}

func NewJWTMaker

func NewJWTMaker(secretKey string) (Maker, error)

NewJWTMaker create a JWT token maker follow the Maker interface

func NewMaker

func NewMaker(key, _type string) (Maker, error)

func NewPasetoMaker

func NewPasetoMaker(symmetricKey string) (Maker, error)

NewPasetoMaker create a paseto token maker follow the Maker interface

type PasetoMaker

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

func (*PasetoMaker) CreateToken

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

CreateToken returns token, payload if creates token that specified username and duration success else error

func (*PasetoMaker) VerifyToken

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

VerifyToken return the payload if the token is valid passed else error

type Payload

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

func NewPayload

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

func (*Payload) Valid

func (p *Payload) Valid() error

Jump to

Keyboard shortcuts

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