store

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package store defines auth session persistence used by auth/jwt. Package store 定义 auth/jwt 使用的认证会话持久化。

Package store defines auth session persistence used by auth/jwt. Package store 定义 auth/jwt 使用的认证会话持久化。

Package store defines auth session persistence used by auth/jwt. Package store 定义 auth/jwt 使用的认证会话持久化。

Index

Constants

This section is empty.

Variables

View Source
var ErrStoreUnavailable = errors.New("token store unavailable")

Functions

This section is empty.

Types

type MemoryStore

type MemoryStore struct {
	// contains filtered or unexported fields
}

MemoryStore keeps user versions and sessions in process memory. MemoryStore 将用户版本与 session 保存在进程内存中。

Usage / 用法:

store := authstore.NewMemoryStore()
mgr, _ := jwt.New("signing-key...", store)

func NewMemoryStore

func NewMemoryStore() *MemoryStore

NewMemoryStore builds a MemoryStore with periodic pruning. NewMemoryStore 构建带周期清理的 MemoryStore。

func (*MemoryStore) BumpUserVersion

func (s *MemoryStore) BumpUserVersion(ctx context.Context, userID string) (int64, error)

BumpUserVersion invalidates all outstanding sessions for a user. BumpUserVersion 通过提升版本让某用户全部 session 失效。

func (*MemoryStore) CreateSession

func (s *MemoryStore) CreateSession(ctx context.Context, sessionID string, state SessionState) error

CreateSession stores a session in memory. CreateSession 将 session 写入内存。

func (*MemoryStore) Prune

func (s *MemoryStore) Prune()

Prune removes expired sessions. Prune 清理过期 session。

func (*MemoryStore) RevokeSession

func (s *MemoryStore) RevokeSession(ctx context.Context, sessionID string) error

RevokeSession deletes a session entry. RevokeSession 删除某个 session。

func (*MemoryStore) RotateRefresh

func (s *MemoryStore) RotateRefresh(ctx context.Context, sessionID, userID string, expectedVersion int64, oldRefreshID, newRefreshID string, exp time.Time) (bool, error)

RotateRefresh atomically replaces the refresh state for a session. RotateRefresh 在内存中原子替换某个 session 的 refresh 状态。

func (*MemoryStore) Session

func (s *MemoryStore) Session(ctx context.Context, sessionID string) (SessionState, bool, error)

Session returns a stored session when still active. Session 返回仍然活跃的已存储 session。

func (*MemoryStore) UserVersion

func (s *MemoryStore) UserVersion(ctx context.Context, userID string) (int64, error)

UserVersion returns the current version for a user. UserVersion 返回用户当前版本。

type RedisOptions

type RedisOptions struct {
	Prefix       string
	WriteTimeout time.Duration
	ReadTimeout  time.Duration
}

RedisOptions configures RedisStore behavior. RedisOptions 配置 RedisStore 行为。

type RedisStore

type RedisStore struct {
	// contains filtered or unexported fields
}

RedisStore persists user versions and sessions in Redis. RedisStore 将用户版本与 session 持久化到 Redis。

func NewRedisStore

func NewRedisStore(client *redis.Client, opts RedisOptions) *RedisStore

NewRedisStore builds a RedisStore with optional prefix/timeouts. NewRedisStore 构建 RedisStore,可选前缀与超时。

func (*RedisStore) BumpUserVersion

func (s *RedisStore) BumpUserVersion(ctx context.Context, userID string) (int64, error)

BumpUserVersion invalidates all outstanding sessions for a user. BumpUserVersion 通过提升版本让某用户全部 session 失效。

func (*RedisStore) CreateSession

func (s *RedisStore) CreateSession(ctx context.Context, sessionID string, state SessionState) error

CreateSession writes a session entry to Redis. CreateSession 写入 session 到 Redis。

func (*RedisStore) RevokeSession

func (s *RedisStore) RevokeSession(ctx context.Context, sessionID string) error

RevokeSession deletes a session entry from Redis. RevokeSession 删除 Redis 中的 session。

func (*RedisStore) RotateRefresh

func (s *RedisStore) RotateRefresh(ctx context.Context, sessionID, userID string, expectedVersion int64, oldRefreshID, newRefreshID string, exp time.Time) (bool, error)

RotateRefresh atomically replaces the refresh state for a session. RotateRefresh 在 Redis 中原子替换某个 session 的 refresh 状态。

func (*RedisStore) Session

func (s *RedisStore) Session(ctx context.Context, sessionID string) (SessionState, bool, error)

Session returns a session entry from Redis. Session 返回 Redis 中的 session。

func (*RedisStore) UserVersion

func (s *RedisStore) UserVersion(ctx context.Context, userID string) (int64, error)

UserVersion returns the current version for a user. UserVersion 返回用户当前版本。

type SessionState

type SessionState struct {
	UserID    string
	RefreshID string
	ExpiresAt time.Time
}

SessionState stores the minimal server-side state required for refresh rotation and session revocation. SessionState 保存 refresh 轮换与 session 吊销所需的最小服务端状态。

type SessionStore

type SessionStore interface {
	UserVersion(ctx context.Context, userID string) (int64, error)
	BumpUserVersion(ctx context.Context, userID string) (int64, error)
	CreateSession(ctx context.Context, sessionID string, state SessionState) error
	Session(ctx context.Context, sessionID string) (SessionState, bool, error)
	RotateRefresh(ctx context.Context, sessionID, userID string, expectedVersion int64, oldRefreshID, newRefreshID string, exp time.Time) (bool, error)
	RevokeSession(ctx context.Context, sessionID string) error
}

SessionStore persists user version state and active sessions. SessionStore 持久化用户版本状态与活跃 session。

UserVersion/BumpUserVersion provide user-wide revocation. CreateSession/Session/RotateRefresh/RevokeSession provide session-level revocation and refresh rotation.

Jump to

Keyboard shortcuts

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