token

package
v0.0.0-...-d2ff1c5 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 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 JWTMaker

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

JWTMaker is a JSON Web Token maker.

func (*JWTMaker) CreateToken

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

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

func (*JWTMaker) VerifyToken

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

VerifyToken checks if the token is valid or not.

type PasteoMaker

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

PasteoMaker is a real implementation of the TokenMaker interface.

func (*PasteoMaker) CreateToken

func (maker *PasteoMaker) CreateToken(username string, duration time.Duration) (string, error)

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

func (*PasteoMaker) VerifyToken

func (maker *PasteoMaker) VerifyToken(token string) (*Payload, error)

VerifyToken checks if the token is valid or not.

type Payload

type Payload struct {
	ID       uuid.UUID `json:"id"`
	Username string    `json:"username"`
	IssueAt  time.Time `json:"issue_at"`
	ExpireAt time.Time `json:"expire_at"`
}

Payload is the output of the token creation process.

func NewPayload

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

NewPayload creates a new payload for a specific username and duration.

type TokenMaker

type TokenMaker interface {
	// CreateToken creates a new token for a specific username and duration.
	CreateToken(username string, duration time.Duration) (string, error)

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

TokenMaker is an interface that creates and verifies tokens.

func NewJWTMaker

func NewJWTMaker(secretKey string) (TokenMaker, error)

NewJWTMaker creates a new JWTMaker.

func NewPasteoMaker

func NewPasteoMaker(symmetricKey string) (TokenMaker, error)

NewPasteoMaker creates a new PasteoMaker.

Jump to

Keyboard shortcuts

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