Documentation
¶
Overview ¶
Package authsession为Bearer认证复用PrismGo Session存储、编码、加密和锁。
Index ¶
- Variables
- func Hash(token string) string
- type Record
- type Store
- func (s *Store) Authenticate(ctx context.Context, token string, refresh bool) (Record, error)
- func (s *Store) Create(ctx context.Context, r Record, accessTTL, refreshTTL time.Duration) (Record, string, string, error)
- func (s *Store) List(ctx context.Context, userID uint, cursor uint64, count int64) ([]Record, uint64, error)
- func (s *Store) Read(ctx context.Context, id string) (Record, error)
- func (s *Store) Refresh(ctx context.Context, token string, accessTTL, refreshTTL time.Duration) (string, string, error)
- func (s *Store) Revoke(ctx context.Context, id string) error
- func (s *Store) RevokeUsers(ctx context.Context, ids ...uint) error
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrUnauthenticated = errors.New("登录已失效")
Functions ¶
Types ¶
type Record ¶
type Record struct {
UserType string `json:"user_type,omitempty"` // 签发时的用户类型,防止旧游客凭证随账号升级
ID string `json:"id"`
UserID uint `json:"user_id"`
AppID uint `json:"app_id,omitempty"`
Verified bool `json:"verified,omitempty"`
ExpiresAt int64 `json:"expires_at"`
RefreshExpiresAt int64 `json:"-"`
CreatedAt int64 `json:"created_at"`
IP string `json:"ip,omitempty"`
UserAgent string `json:"user_agent,omitempty"`
AccessHash string `json:"-"`
RefreshHash string `json:"-"`
}
Record仅保存身份和设备信息,账号状态和权限仍从业务层读取。
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store按admin/user隔离凭证,索引用于设备列表和撤销全部设备。
func (*Store) Authenticate ¶
func (*Store) Create ¶
func (s *Store) Create(ctx context.Context, r Record, accessTTL, refreshTTL time.Duration) (Record, string, string, error)
Create只保存凭证摘要;访客不需要独立刷新凭证。
func (*Store) List ¶
func (s *Store) List(ctx context.Context, userID uint, cursor uint64, count int64) ([]Record, uint64, error)
List使用Redis游标读取设备,不伪造总数或按页截断扫描结果。
Click to show internal directories.
Click to hide internal directories.