auth

package
v0.0.0-...-74adf86 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidToken is returned when a token is invalid
	ErrInvalidToken = errors.New("invalid token")
	// ErrExpiredToken is returned when a token has expired
	ErrExpiredToken = errors.New("token has expired")
	// ErrMissingToken is returned when a token is missing
	ErrMissingToken = errors.New("token is missing")
)

Functions

This section is empty.

Types

type Claims

type Claims struct {
	Username string `json:"username"`
	IsAdmin  bool   `json:"is_admin"`
	jwt.RegisteredClaims
}

Claims represents the JWT claims for a session

type SessionManager

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

SessionManager handles JWT token generation and validation

func NewSessionManager

func NewSessionManager() (*SessionManager, error)

NewSessionManager creates a new session manager Expects JWT_SECRET environment variable for production

func (*SessionManager) GenerateToken

func (sm *SessionManager) GenerateToken(username string, isAdmin bool) (string, error)

GenerateToken creates a new JWT token for a user

func (*SessionManager) GetTokenDuration

func (sm *SessionManager) GetTokenDuration() time.Duration

GetTokenDuration returns the configured token duration

func (*SessionManager) GetTokenExpiry

func (sm *SessionManager) GetTokenExpiry(tokenString string) (time.Time, error)

GetTokenExpiry returns the expiration time for a token

func (*SessionManager) RefreshToken

func (sm *SessionManager) RefreshToken(tokenString string) (string, error)

RefreshToken generates a new token from an existing valid token

func (*SessionManager) RevokeToken

func (sm *SessionManager) RevokeToken(tokenString string) error

RevokeToken invalidates a token (for logout) Note: JWT tokens are stateless, so true revocation requires a blacklist For now, this is a placeholder that returns success A production implementation would store revoked tokens in Redis/database

func (*SessionManager) ValidateToken

func (sm *SessionManager) ValidateToken(tokenString string) (*Claims, error)

ValidateToken validates a JWT token and returns the claims

Jump to

Keyboard shortcuts

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