token

package
v0.0.0-...-c29c528 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RefreshTokenType = "refresh"
	AccessTokenType  = "access"
)

Variables

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

Functions

This section is empty.

Types

type JWTMaker

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

func (*JWTMaker) CreateToken

func (maker *JWTMaker) CreateToken(userId int32, duration time.Duration, tokenType string) (string, *Payload, error)

func (*JWTMaker) VerifyToken

func (maker *JWTMaker) VerifyToken(token string, tokenType string) (*Payload, error)

type Maker

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

func NewJWTMaker

func NewJWTMaker(secretKey string) (Maker, error)

type Payload

type Payload struct {
	Id        uuid.UUID `json:"id"`
	UserId    int32     `json:"username"`
	TokenType string    `json:"token_type"`
	IssuedAt  time.Time `json:"issued_at"`
	ExpiredAt time.Time `json:"expired_at"`
}

func NewPayload

func NewPayload(userId int32, duration time.Duration, tokenType string) (*Payload, error)

func (*Payload) Valid

func (payload *Payload) Valid() error

Jump to

Keyboard shortcuts

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