token

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidJWTKeySize     = errors.New(fmt.Sprintf("Invalid key size: must be at least %v characters", minJWTSecretKeySize))
	ErrMissingCustomDuration = errors.New("Duration must be provided for CustomToken")
	ErrTooManyCustomDuration = errors.New("Provide too many durations")
	ErrInvalidTokenType      = errors.New("Invalid token type")
)
View Source
var (
	ErrInvalidToken = errors.New("Token is invalid")
	ErrExpiredToken = errors.New("Token has expired")
)
View Source
var (
	ErrInvalidPasetoKeySize = errors.New(fmt.Sprintf("Invalid key size: must be exactly %d charaters", pasetoSymmetricKeySize))
)

Functions

func NewJWTMaker

func NewJWTMaker(id string) *jwtMaker

func NewPasetoMaker

func NewPasetoMaker(id string) *pasetoMaker

Types

type Payload

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

Payload contains the payload data of the token

func NewPayload

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

NewPayload creates a new token payload with a specific username and duration

func (*Payload) Valid

func (payload *Payload) Valid() error

Valid checks if the token payload is valid or not

type TokenMaker

type TokenMaker interface {
	// CreateToken creates a new token for a specific uid and duration
	// For TokenType CustomToken, duration must be provided explicitly.
	CreateToken(tokenType TokenType, uid string, duration ...time.Duration) (string, *Payload, error)

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

type TokenType

type TokenType int
const (
	AccessToken TokenType = iota
	RefreshToken
	CustomToken
)

Jump to

Keyboard shortcuts

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