auth

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2025 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

type Claims

type Claims struct {
	UserID int    `json:"user_id"`
	Email  string `json:"email"`
}

Claims represent the JWT token claims

type Operator

type Operator struct {
	Enable      bool
	JWTSecret   string
	JWTDuration time.Duration
}

func NewOperator

func NewOperator(enable bool, secret string, duration time.Duration) *Operator

func (*Operator) GenerateToken

func (h *Operator) GenerateToken(user Claims) (TokenResponse, error)

GenerateToken creates a new JWT token for a user

func (*Operator) GenerateTokenWithTTL added in v1.2.0

func (h *Operator) GenerateTokenWithTTL(
	user Claims,
	ttl time.Duration,
) (TokenResponse, error)

func (*Operator) ValidateToken

func (h *Operator) ValidateToken(tokenString string) (Claims, error)

ValidateToken validates and parses the JWT token

type TokenResponse

type TokenResponse struct {
	Token     string    `json:"token"`
	ExpiresAt time.Time `json:"expires_at"`
}

TokenResponse represents the response after successful login

Jump to

Keyboard shortcuts

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