Documentation
¶
Overview ¶
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 sessions in memory. MemoryStore 在内存中保存 session。
func NewMemoryStore ¶
func NewMemoryStore() *MemoryStore
NewMemoryStore returns an in-memory SessionStore. NewMemoryStore 返回内存版 SessionStore。
func (*MemoryStore) BumpUserVersion ¶
BumpUserVersion invalidates all sessions for userID. BumpUserVersion 通过提升版本使 userID 的全部 session 失效。
func (*MemoryStore) CreateSession ¶
func (s *MemoryStore) CreateSession(ctx context.Context, sessionID string, state SessionState) error
CreateSession stores a session. 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. 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 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 the session when still active. Session 返回仍然活跃的 session。
func (*MemoryStore) UserVersion ¶
UserVersion returns the current version for userID. UserVersion 返回 userID 的当前版本。
type RedisOptions ¶
RedisOptions configures NewRedisStore. RedisOptions 配置 NewRedisStore。
type RedisStore ¶
type RedisStore struct {
// contains filtered or unexported fields
}
RedisStore stores sessions in Redis. RedisStore 在 Redis 中保存 session。
func NewRedisStore ¶
func NewRedisStore(client *redis.Client, opts RedisOptions) *RedisStore
NewRedisStore returns a Redis-backed SessionStore. NewRedisStore 返回 Redis 版 SessionStore。
func (*RedisStore) BumpUserVersion ¶
BumpUserVersion invalidates all sessions for userID. BumpUserVersion 通过提升版本使 userID 的全部 session 失效。
func (*RedisStore) CreateSession ¶
func (s *RedisStore) CreateSession(ctx context.Context, sessionID string, state SessionState) error
CreateSession stores a session. CreateSession 保存 session。
func (*RedisStore) RevokeSession ¶
func (s *RedisStore) RevokeSession(ctx context.Context, sessionID string) error
RevokeSession deletes a session. RevokeSession 删除 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 replaces the refresh state for a session. RotateRefresh 替换某个 session 的 refresh 状态。
func (*RedisStore) Session ¶
func (s *RedisStore) Session(ctx context.Context, sessionID string) (SessionState, bool, error)
Session returns the session when still active. Session 返回仍然活跃的 session。
func (*RedisStore) UserVersion ¶
UserVersion returns the current version for userID. UserVersion 返回 userID 的当前版本。
type SessionState ¶
SessionState stores session state for refresh rotation and 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 versions and active sessions. Backend availability failures must be normalized to ErrStoreUnavailable. SessionStore 持久化用户版本与活跃 session。 后端可用性错误必须统一为 ErrStoreUnavailable。