session

package
v0.0.1-dev.137 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package session implements RUNE-201 refresh-token rotation with a grace window. It is transport-neutral: both the browser-facing HTTP cookie endpoint (pkg/api/server) and the CLI-facing gRPC AuthService.Refresh RPC (pkg/api/service) drive the same Manager instance, so the in-memory grace cache is shared across both surfaces. Living in its own package avoids a service↔server import cycle.

Index

Constants

View Source
const (
	DefaultAccessTTL   = 15 * time.Minute
	DefaultRefreshTTL  = 30 * 24 * time.Hour // sliding idle window
	DefaultGraceWindow = 30 * time.Second    // tolerate concurrent-refresh races
)

RUNE-201 session parameters. Defaults; promoted to config later if needed.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	AccessTTL   time.Duration
	RefreshTTL  time.Duration
	GraceWindow time.Duration
	// contains filtered or unexported fields
}

Manager implements refresh-token rotation with a grace window. Rotations are serialized by mu to keep the cache and the store consistent (single-server MVP; refresh volume is low).

func New

func New(st store.Store, logger log.Logger) *Manager

New constructs a Manager with default TTLs.

func (*Manager) Rotate

func (m *Manager) Rotate(ctx context.Context, secret string) (Out, Result)

Rotate validates the presented refresh secret and returns fresh credentials. See Result for the outcome classification.

type Out

type Out struct {
	Access    string
	Refresh   string
	AccessExp *time.Time
}

Out carries the credentials handed back to the caller.

type Result

type Result int

Result classifies the outcome of a refresh attempt.

const (
	ResultOK      Result = iota // rotated (or served a within-grace successor)
	ResultBreach                // stale reuse past grace → grant revoked (theft)
	ResultInvalid               // unknown/expired/non-refresh secret
	ResultError                 // internal error
)

Jump to

Keyboard shortcuts

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