Help us shape the future of Go! Take the 2026 Go Developer Survey

devicesession

package
v1.21.2 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package devicesession supplies per-device session generations. Rotating a generation revokes all sessions for that device, including offline clients, without scanning Redis or affecting the user's other sessions.

Index

Constants

View Source
const (
	IDClaim    = "DeviceId"
	EpochClaim = "DeviceEpoch"
)

Variables

This section is empty.

Functions

func AcquireEpoch

func AcquireEpoch(ctx context.Context, client Store, id int64) (string, error)

AcquireEpoch is used only when issuing a new, authenticated session. A missing generation during token validation must never default to an old value: eviction of a key must not resurrect a previously revoked token.

func Binding

func Binding(claims map[string]any) (id int64, epoch string, err error)

Binding rejects malformed and legacy unbound device sessions. IDs are strings so JSON's float64 conversion cannot round a database ID.

func Epoch

func Epoch(ctx context.Context, client Store, id int64) (string, error)

func Revoke

func Revoke(ctx context.Context, client Store, id int64) error

Types

type Store added in v1.21.0

type Store interface {
	Get(ctx context.Context, key string) *redis.StringCmd
	Set(ctx context.Context, key string, value any, expiration time.Duration) *redis.StatusCmd
	SetNX(ctx context.Context, key string, value any, expiration time.Duration) *redis.BoolCmd
}

Store is the Redis surface the generations use; *redis.Client satisfies it.

Jump to

Keyboard shortcuts

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