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 ¶
- Variables
- type MemoryStore
- func (s *MemoryStore) BumpUserVersion(ctx context.Context, userID string) (int64, error)
- func (s *MemoryStore) CreateSession(ctx context.Context, sessionID string, state SessionState) error
- func (s *MemoryStore) Prune()
- func (s *MemoryStore) RevokeSession(ctx context.Context, sessionID string) error
- func (s *MemoryStore) RotateRefresh(ctx context.Context, sessionID, userID string, expectedVersion int64, ...) (bool, error)
- func (s *MemoryStore) Session(ctx context.Context, sessionID string) (SessionState, bool, error)
- func (s *MemoryStore) UserVersion(ctx context.Context, userID string) (int64, error)
- type RedisOptions
- type RedisStore
- func (s *RedisStore) BumpUserVersion(ctx context.Context, userID string) (int64, error)
- func (s *RedisStore) CreateSession(ctx context.Context, sessionID string, state SessionState) error
- func (s *RedisStore) RevokeSession(ctx context.Context, sessionID string) error
- func (s *RedisStore) RotateRefresh(ctx context.Context, sessionID, userID string, expectedVersion int64, ...) (bool, error)
- func (s *RedisStore) Session(ctx context.Context, sessionID string) (SessionState, bool, error)
- func (s *RedisStore) UserVersion(ctx context.Context, userID string) (int64, error)
- type SessionState
- type SessionStore
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
UserVersion returns the current version for a user. UserVersion 返回用户当前版本。
type RedisOptions ¶
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 ¶
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 ¶
UserVersion returns the current version for a user. UserVersion 返回用户当前版本。
type SessionState ¶
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.