session

package
v1.2.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	DefaultGrace      = 60 * time.Second
	DefaultHealWindow = 24 * time.Hour
	DefaultMaxChain   = 8
)

Variables

View Source
var (
	ErrRefreshNotFound = errors.New("session: refresh token not found")
	ErrRefreshInvalid  = errors.New("session: refresh token is not valid")
	ErrRefreshReused   = errors.New("session: superseded refresh token reused, sessions revoked")
)

Functions

This section is empty.

Types

type Kind added in v1.2.0

type Kind int
const (
	Rotated Kind = iota + 1
	Absorbed
	Healed
	HealedElsewhere
)

type Manager

type Manager struct {
	Store         Store
	CacheTTL      time.Duration
	CacheDisabled bool
}

func (*Manager) Revoke

func (m *Manager) Revoke(ctx context.Context, userID int64, sid string) error

func (*Manager) RevokeAll

func (m *Manager) RevokeAll(ctx context.Context, userID int64, except string) error

func (*Manager) Touch

func (m *Manager) Touch(ctx context.Context, userID int64, sid string)

func (*Manager) Valid

func (m *Manager) Valid(ctx context.Context, userID int64, sid string) (bool, error)

type Minted added in v1.2.0

type Minted struct {
	Token   string
	Hash    string
	Expires time.Time
}

type Outcome added in v1.2.0

type Outcome struct {
	Kind     Kind
	UserID   int64
	SID      string
	NewToken string
}

type RefreshRecord added in v1.2.0

type RefreshRecord struct {
	UserID        int64
	SID           string
	Expired       bool
	Superseded    bool
	SupersededAgo time.Duration
	SupersededBy  string
}

type RefreshStore added in v1.2.0

type RefreshStore interface {
	Find(ctx context.Context, hash string) (RefreshRecord, error)
	Rotate(ctx context.Context, old RefreshRecord, oldHash, newHash string, userID int64, sid string, newExpiry time.Time) (bool, error)
}

type Refresher added in v1.2.0

type Refresher struct {
	Store      RefreshStore
	Sessions   *Manager
	Grace      time.Duration
	HealWindow time.Duration
	MaxChain   int
}

func (*Refresher) Refresh added in v1.2.0

func (r *Refresher) Refresh(ctx context.Context, presentedHash string, sameDevice func() bool, mint func(userID int64, sid string) (Minted, error)) (Outcome, error)

type Store

type Store interface {
	Alive(ctx context.Context, userID int64, sid string) (bool, error)
	Revoke(ctx context.Context, userID int64, sid string) error
	RevokeAll(ctx context.Context, userID int64, except string) ([]string, error)
}

Jump to

Keyboard shortcuts

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