authsession

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package authsession为Bearer认证复用PrismGo Session存储、编码、加密和锁。

Index

Constants

This section is empty.

Variables

View Source
var ErrUnauthenticated = errors.New("登录已失效")

Functions

func Hash

func Hash(token string) string

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 New

func New(scope string) (*Store, error)

func (*Store) Authenticate

func (s *Store) Authenticate(ctx context.Context, token string, refresh bool) (Record, error)

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游标读取设备,不伪造总数或按页截断扫描结果。

func (*Store) Read

func (s *Store) Read(ctx context.Context, id string) (Record, error)

Read同时检查可撤销索引,孤立payload不能恢复已注销的登录。

func (*Store) Refresh

func (s *Store) Refresh(ctx context.Context, token string, accessTTL, refreshTTL time.Duration) (string, string, error)

Refresh使用框架锁串行轮转,同一个刷新凭证只能成功一次。

func (*Store) Revoke

func (s *Store) Revoke(ctx context.Context, id string) error

func (*Store) RevokeUsers

func (s *Store) RevokeUsers(ctx context.Context, ids ...uint) error

RevokeUsers先删除有效索引,刷新中途写回payload也不能恢复登录。

Jump to

Keyboard shortcuts

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