auth

package
v0.0.0-...-17f2f0b Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const MIN_SECRET_KEY_SIZE = 32

Variables

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

Different types of error returned by the VerifyToken function

Functions

This section is empty.

Types

type Authenticator

type Authenticator interface {
	// CreateToken creates a new token for a specific client sub and duration
	CreateToken(sub uuid.UUID, role string, duration time.Duration) (string, *Payload, error)

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

Authenticator is an interface for managing tokens

func CreateJWTAuditor

func CreateJWTAuditor(secretKey string) (Authenticator, error)

func CreatePasetoAuditor

func CreatePasetoAuditor(symmetricKey string) (Authenticator, error)

type JWTAuditor

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

func (*JWTAuditor) CreateToken

func (auditor *JWTAuditor) CreateToken(sub uuid.UUID, role string, duration time.Duration) (string, *Payload, error)

func (*JWTAuditor) VerifyToken

func (auditor *JWTAuditor) VerifyToken(token string) (*Payload, error)

type PasetoAuditor

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

func (*PasetoAuditor) CreateToken

func (auditor *PasetoAuditor) CreateToken(sub uuid.UUID, role string, duration time.Duration) (string, *Payload, error)

func (*PasetoAuditor) VerifyToken

func (auditor *PasetoAuditor) VerifyToken(token string) (*Payload, error)

type Payload

type Payload struct {
	ID      uuid.UUID `json:"id"`
	Sub     uuid.UUID `json:"sub"`
	Role    string    `json:"role"`
	Issued  time.Time `json:"issued"`
	Expired time.Time `json:"expired"`
}

Payload contains the payload data of the token

func CreatePayload

func CreatePayload(sub uuid.UUID, role string, duration time.Duration) (*Payload, error)

CreatePayload 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

Jump to

Keyboard shortcuts

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