session

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package session handles session and token storage for authentication.

Index

Constants

View Source
const TokenRenewalBuffer = 5 * time.Minute

TokenRenewalBuffer is the duration before expiry when a token is considered to need renewal (5 minutes)

Variables

This section is empty.

Functions

func ExtractRawToken

func ExtractRawToken(tokenData string) string

ExtractRawToken extracts the raw machine token value from a token string. PHP Terminus stores tokens as JSON with token, email, and date fields. This function handles both formats: raw token strings and PHP-style JSON.

Types

type Session

type Session struct {
	SessionToken string `json:"session"`
	UserID       string `json:"user_id"`
	ExpiresAt    int64  `json:"expires_at"`
	Email        string `json:"email,omitempty"`
}

Session represents an authenticated session

func (*Session) IsExpired

func (s *Session) IsExpired() bool

IsExpired returns true if the session has expired

func (*Session) NeedsRenewal added in v0.7.0

func (s *Session) NeedsRenewal() bool

NeedsRenewal returns true if the session token will expire within the renewal buffer window (5 minutes) or has already expired

type Store

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

Store handles session and token persistence

func NewStore

func NewStore(cacheDir string) *Store

NewStore creates a new session store

func (*Store) DeleteSession

func (s *Store) DeleteSession() error

DeleteSession deletes the session file

func (*Store) DeleteToken

func (s *Store) DeleteToken(email string) error

DeleteToken deletes a machine token

func (*Store) ListTokens

func (s *Store) ListTokens() ([]string, error)

ListTokens returns a list of saved token emails

func (*Store) LoadMachineToken added in v0.7.0

func (s *Store) LoadMachineToken(email string) (string, error)

LoadMachineToken loads and extracts the raw machine token for an email. This handles both PHP Terminus JSON format and raw token strings.

func (*Store) LoadSession

func (s *Store) LoadSession() (*Session, error)

LoadSession loads a session from disk Note: This returns expired sessions as well, since the machine token can still be used for automatic token renewal. Callers should check IsExpired() if they need to verify the session is still valid.

func (*Store) LoadToken

func (s *Store) LoadToken(email string) (string, error)

LoadToken loads a machine token from disk (returns raw file content)

func (*Store) SaveSession

func (s *Store) SaveSession(session *Session) error

SaveSession saves a session to disk

func (*Store) SaveToken

func (s *Store) SaveToken(email, token string) error

SaveToken saves a machine token to disk in PHP Terminus compatible JSON format

Jump to

Keyboard shortcuts

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