Documentation
¶
Overview ¶
Package auth 拥有 MCP owner 与 OAuth 的私有状态,不接触产品账号凭据。
Index ¶
- Variables
- type Client
- type Grant
- type Handler
- type State
- type Store
- func (s Store) Init(ctx context.Context, reset bool) (string, error)
- func (s Store) InitializePixivUser(ctx context.Context, userID int64) (int64, error)
- func (s Store) Read(ctx context.Context) (State, error)
- func (s Store) SelectPixivUser(ctx context.Context, userID int64) error
- func (s Store) SelectPixivUserIf(ctx context.Context, userID int64, eligible func(int64) (bool, error)) (bool, error)
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
ClientName string `json:"client_name"`
RedirectURIs []string `json:"redirect_uris"`
// 只由 owner 同意流程设置,防止匿名注册挤掉已签发授权码的客户端。
OwnerApproved bool `json:"owner_approved,omitempty"`
}
Client 记录 public client metadata 与本地批准标记;map key 是 client ID,不保存 secret。
type Grant ¶
type Grant struct {
ClientID string `json:"client_id"`
Resource string `json:"resource"`
Scope string `json:"scope"`
AccessTokens map[string]time.Time `json:"access_tokens"`
RefreshHash string `json:"refresh_hash"`
UsedRefreshHashes []string `json:"used_refresh_hashes"`
Revoked bool `json:"revoked"`
}
Grant 持久化 token verifier 而非原值;已用 refresh hashes 留给重放撤销检查。
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler 同时持有 OAuth 路由及 canonical resource 的 bearer 边界,不管理 listener。
func NewHandler ¶
NewHandler 构造独立 discovery/DCR/authorize/token handler 及 bearer 包装器;canonicalBase 不从请求头推断。 不启动 listener 或读取文件;注册、授权与 token 操作要求 store 已初始化,并在每次请求内读取最新状态。
func (*Handler) RequireBearer ¶
RequireBearer 包装 MCP handler;鉴权只影响新请求,不取消已授权请求。
func (*Handler) RequireCanonical ¶
RequireCanonical 将入站 Host/Origin 绑定到配置的部署地址,不信任转发头。
type State ¶
type State struct {
Version int `json:"version"`
OwnerVerifier string `json:"owner_verifier"`
Clients map[string]Client `json:"clients"`
Grants map[string]Grant `json:"grants"`
SelectedPixivUserID int64 `json:"selected_pixiv_user_id"`
}
State 是唯一持久合同;owner verifier 同时是内存授权会话/code 的 generation。
type Store ¶
type Store struct{ Path string }
Store 只持有路径;每次操作从原子文件读取当前状态,不缓存 verifier。
func (Store) InitializePixivUser ¶
InitializePixivUser adopts the initial account only if no selection has committed yet.
func (Store) SelectPixivUser ¶
SelectPixivUser 只保存账号 ID;调用方先核验本地账号,不在此复制凭据或修改 CLI default。
func (Store) SelectPixivUserIf ¶
func (s Store) SelectPixivUserIf(ctx context.Context, userID int64, eligible func(int64) (bool, error)) (bool, error)
SelectPixivUserIf checks local eligibility and commits under the same state lock. eligible must not write MCP state; it receives identity only, never credentials.