Documentation ¶
Overview ¶
Package goPasetoV4 provides an implementation of the Maker interface using Paseto (Platform-Agnostic Security Tokens). It includes functionality to create and verify tokens securely.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrExpiredToken = errors.New("token has expired") ErrInvalidToken = errors.New("token is invalid") )
Functions ¶
This section is empty.
Types ¶
type Maker ¶
type Maker interface { // CreateToken creates a new token for a specific username and duration CreateToken(username string, duration time.Duration) (string, *Payload, error) // VerifyToken checks if the provided token is valid or not VerifyToken(token string) (*Payload, error) }
Maker is an interface for managing tokens
func NewPasetoMaker ¶
func NewPasetoMaker() Maker
NewPasetoMaker initializes and returns a new PasetoMaker. It attempts to acquire a nonce from the PASETO_NONCE environment variable. If not available, it generates a random nonce. This function returns a Maker interface.
type PasetoMaker ¶
type PasetoMaker struct {
// contains filtered or unexported fields
}
PasetoMaker is a struct that implements the Maker interface. It provides methods for creating and verifying Paseto tokens.
func (*PasetoMaker) CreateToken ¶
func (maker *PasetoMaker) CreateToken(username string, duration time.Duration) (string, *Payload, error)
CreateToken generates a new Paseto token for a given username and duration. It returns an encrypted token string and the Payload struct, or an error if the token generation fails.
func (*PasetoMaker) VerifyToken ¶
func (maker *PasetoMaker) VerifyToken(token string) (*Payload, error)
VerifyToken checks the validity of a provided Paseto token. It returns a Payload struct if the token is valid or an error if it is invalid or expired.
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"` }
Payload contains the payload data of a token
func NewPayload ¶
NewPayload creates a new payload with a specific username and duration