Documentation
¶
Overview ¶
Package session handles session and token storage for authentication.
Index ¶
- Constants
- func ExtractRawToken(tokenData string) string
- type Session
- type Store
- func (s *Store) DeleteSession() error
- func (s *Store) DeleteToken(email string) error
- func (s *Store) ListTokens() ([]string, error)
- func (s *Store) LoadMachineToken(email string) (string, error)
- func (s *Store) LoadSession() (*Session, error)
- func (s *Store) LoadToken(email string) (string, error)
- func (s *Store) SaveSession(session *Session) error
- func (s *Store) SaveToken(email, token string) error
Constants ¶
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 ¶
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) NeedsRenewal ¶ added in v0.7.0
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 (*Store) DeleteSession ¶
DeleteSession deletes the session file
func (*Store) DeleteToken ¶
DeleteToken deletes a machine token
func (*Store) ListTokens ¶
ListTokens returns a list of saved token emails
func (*Store) LoadMachineToken ¶ added in v0.7.0
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 ¶
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) SaveSession ¶
SaveSession saves a session to disk