Documentation
¶
Overview ¶
Package sessiontoken manages opaque server-side sessions.
Index ¶
- Variables
- type Cache
- type Config
- type ExtensionConfig
- type Issued
- type Manager
- func (manager *Manager) Create(ctx context.Context, subjectID string) (Issued, error)
- func (manager *Manager) List(ctx context.Context, subjectID string) ([]Record, error)
- func (manager *Manager) Resolve(ctx context.Context, rawToken string) (Record, error)
- func (manager *Manager) Revoke(ctx context.Context, rawToken string) error
- func (manager *Manager) RevokeAll(ctx context.Context, subjectID string) error
- func (manager *Manager) RevokeByID(ctx context.Context, subjectID, sessionID string) error
- func (manager *Manager) Rotate(ctx context.Context, rawToken string) (Issued, error)
- type Record
- type Store
- type TokenHash
Constants ¶
This section is empty.
Variables ¶
var ( ErrCacheMiss = errors.New("session cache miss") ErrCacheSync = errors.New("session cache synchronization failed") ErrConflict = errors.New("session credential conflict") ErrInactive = errors.New("session is inactive") ErrInvalidConfig = errors.New("invalid session configuration") ErrInvalidRecord = errors.New("invalid session record") ErrInvalidToken = token.ErrInvalidToken ErrNotFound = errors.New("session not found") )
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface {
Get(ctx context.Context, tokenHash TokenHash) (Record, error)
Set(ctx context.Context, record Record, ttl time.Duration) error
Delete(ctx context.Context, tokenHash TokenHash) error
}
Cache is an optional bounded-TTL acceleration layer.
type ExtensionConfig ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func (*Manager) Create ¶
Create commits a new session to durable storage before returning its raw credential. A cache population failure does not change durable success.
func (*Manager) List ¶
List returns the durable sessions for a subject. Inactive sessions are included so callers can show session history and decide what to remove.
func (*Manager) Resolve ¶
Resolve validates a raw credential and resolves active server-side state. Cache failure or invalid cached state falls back to the durable authority.
func (*Manager) RevokeAll ¶
RevokeAll durably invalidates every session for a subject, then removes cached state for the affected sessions. Durable success is retained when cache invalidation fails and ErrCacheSync is returned for retry handling.
func (*Manager) RevokeByID ¶
RevokeByID revokes a session only when it belongs to the supplied subject.
type Record ¶
type Record struct {
ID string
SubjectID string
TokenHash TokenHash
CreatedAt time.Time
ExpiresAt time.Time
ExtendedAt *time.Time
RevokedAt *time.Time
}
Record is the server-side state associated with an opaque session token.
type Store ¶
type Store interface {
Create(ctx context.Context, record Record) error
FindByTokenHash(ctx context.Context, tokenHash TokenHash) (Record, error)
ListBySubject(ctx context.Context, subjectID string) ([]Record, error)
Extend(ctx context.Context, tokenHash TokenHash, extendedAt, expiresAt time.Time) (Record, error)
Rotate(ctx context.Context, current TokenHash, replacement Record, rotatedAt time.Time) error
Revoke(ctx context.Context, tokenHash TokenHash, revokedAt time.Time) error
RevokeAll(ctx context.Context, subjectID string, revokedAt time.Time) ([]Record, error)
}
Store is the durable authority for sessions.
Extend only increases the expiry of an active record. Rotate atomically invalidates current and creates replacement. Revoke is idempotent.