Documentation
¶
Index ¶
- Constants
- Variables
- func AutomaticPersistentHandlerSupported() bool
- func CallbackRelayURL(callbackURL string) (string, error)
- func ClearRemoteLoginHandoff(start RemoteLoginStart) error
- func DelegateToPrevious(ctx context.Context, rawURL string) error
- func DisablePersistent(ctx context.Context) error
- func EnsurePersistent(ctx context.Context) error
- func EnsurePersistentIfNeeded(ctx context.Context) error
- func Install(ctx context.Context, callbackRelayURL string) (cleanup func(), err error)
- func IsAllowedPixivCallbackURL(rawURL string) bool
- func StartRemoteLogin(ctx context.Context, start RemoteLoginStart) (string, error)
- type CallbackHandlingResult
- type RemoteCallbackSession
- type RemoteLoginStart
- type RemoteLoginStartResponse
Constants ¶
const CallbackCommand = "_callback"
CallbackCommand 是 desktop protocol handler 调回当前 CLI binary 的隐藏入口名。 它只由本包生成的系统关联使用,不是公开 CLI 命令。
const ( // RelayResultURLHeader 只承载一次性、无敏感最终页 URL。server 直到 OAuth // exchange 完成才结束 callback response;client 在此期间打开结果页。 RelayResultURLHeader = "X-Pixiv-Relay-Result-URL" )
Variables ¶
var ( // ErrNoActiveLocalCallback 是持久协议 handler 在没有本轮 loopback 登录时的 // 正常状态;调用方可继续尝试已配置的远程 relay。 ErrNoActiveLocalCallback = errors.New("Pixiv login callback is no longer active") ErrNoConfiguredRelay = errors.New("Pixiv remote login relay is not configured") ErrIncompleteRelayConfig = errors.New("remote login relay configuration is incomplete") )
var ErrNoActiveRemoteLogin = errors.New("no active remote login handoff")
Functions ¶
func AutomaticPersistentHandlerSupported ¶ added in v0.9.0
func AutomaticPersistentHandlerSupported() bool
AutomaticPersistentHandlerSupported 仅对计划中的 desktop client 平台启用启动期 注册。desktop Linux 仍由官方 installer/正常 browser login 处理,headless Linux server 不会因任意命令尝试建立 XDG 关联。
func CallbackRelayURL ¶ added in v0.6.0
CallbackRelayURL 将系统交给 handler 的 pixiv:// URL 放入 bridge fragment。 fragment 不会进入 loopback GET 或浏览器历史;bridge 页面会在 POST ��清除它。
func ClearRemoteLoginHandoff ¶ added in v0.9.0
func ClearRemoteLoginHandoff(start RemoteLoginStart) error
ClearRemoteLoginHandoff 仅在本地 active state 仍然对应 start 时删除它。handler 成功领取 URL 后若浏览器无法启动,应调用此函数;随后 Pixiv callback 会回到此前 的系统 handler,而不会转发给已无法使用的会话。
func DelegateToPrevious ¶ added in v0.8.0
func DisablePersistent ¶ added in v0.8.0
func EnsurePersistent ¶ added in v0.8.0
EnsurePersistent 安装桌面 Linux 的按需 callback handler。headless Linux 不会调用它;server relay 本身不依赖任何桌面集成。
func EnsurePersistentIfNeeded ¶ added in v0.9.0
EnsurePersistentIfNeeded 先以私有 manifest 判断当前 binary 是否已注册;相同 binary 不重复写系统关联。外部修改 association 时,官方 installer 或 browser login 仍会显式重新注册,避免在无关命令中覆盖用户后来选择的默认应用。
func Install ¶
Install 在桌面 Linux 上只为当前 auth login 尝试注册 pixiv:// handler。 xdg-mime 会写入用户 mimeapps 文件,因此在修改前保留所有可能的用户级位置并在 cleanup 时逐字节恢复,避免没有原默认 handler 的用户留下悬挂关联。
func IsAllowedPixivCallbackURL ¶ added in v0.8.0
IsAllowedPixivCallbackURL 是持久协议 handler 的精确白名单。未来若 Pixiv 增加可转发路径,应在这里以 host/path 规则明确扩展,不能把任意 pixiv:// URL 发给远程服务端。
func StartRemoteLogin ¶ added in v0.9.0
func StartRemoteLogin(ctx context.Context, start RemoteLoginStart) (string, error)
StartRemoteLogin 向明确选中的一次性会话领取 OAuth URL,并只保存本次 callback 转发所需的最小私有状态。新的 handoff 会原子替换旧状态。
Types ¶
type CallbackHandlingResult ¶ added in v0.8.0
type CallbackHandlingResult struct {
LocalRelayURL string
RemoteCallback *RemoteCallbackSession
RemoteLoginStart *RemoteLoginStart
}
CallbackHandlingResult 只携带不含授权码或 token 的本地 bridge URL,或 remote relay 返回的一次性最终页 session。callback 本身绝不写入 stdout/stderr。
func HandleCallback ¶ added in v0.8.0
func HandleCallback(ctx context.Context, rawURL string) (CallbackHandlingResult, error)
HandleCallback 是持久系统协议关联调用的唯一入口。正在进行的本地 login 始终 优先;只有没有本地 endpoint 时才尝试由 remote-login 显式建立的一次性 handoff。 非白名单 URL 定向交回先前 handler,不会成为任意 pixiv:// URL 的转发器。
type RemoteCallbackSession ¶ added in v0.8.0
type RemoteCallbackSession struct {
ResultURL string
// contains filtered or unexported fields
}
RemoteCallbackSession 代表已被 server 接收、但尚未完成 OAuth exchange 的一次 callback。ResultURL 只显示固定成功/失败页面;它从不包含 Pixiv code 或 token。
func ForwardActiveRemoteLoginCallback ¶ added in v0.9.0
func ForwardActiveRemoteLoginCallback(ctx context.Context, rawCallbackURL string) (*RemoteCallbackSession, error)
ForwardActiveRemoteLoginCallback 只将官方 callback 交给被 remote-login deep link 明确启动的会话。服务端接收成功即清理私有 transient state,避免后续 callback 被错误重用或转发到旧会话。
func (*RemoteCallbackSession) Abort ¶ added in v0.8.0
func (s *RemoteCallbackSession) Abort()
Abort 仅在浏览器无法打开最终页时释放仍在 server 上等待的 callback 请求。
func (*RemoteCallbackSession) Complete ¶ added in v0.8.0
func (s *RemoteCallbackSession) Complete() error
Complete 等待 server 完成 OAuth exchange。调用方应先打开 ResultURL,再调用它; 这样浏览器可以持续显示“Completing login”,最终得到与 server 一致的结果。
type RemoteLoginStart ¶ added in v0.9.0
RemoteLoginStart 是 session page 交给 desktop handler 的一次性请求。它不包含 OAuth URL、token 或任何持久设备身份;proof 仅绑定这次会话。
func ParseRemoteLoginLink ¶ added in v0.9.0
func ParseRemoteLoginLink(raw string) (RemoteLoginStart, error)
ParseRemoteLoginLink 只接受带完整 proof 的精确内部 deep link,拒绝额外 参数,避免 handler 成为任意 origin 的请求转发器。
type RemoteLoginStartResponse ¶ added in v0.9.0
type RemoteLoginStartResponse struct {
AuthorizationURL string `json:"authorization_url"`
}