auth

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLoginRequired = errors.New("login required")

Functions

func CommitLogin added in v0.1.4

func CommitLogin(ctx context.Context, config ConfigLoader, tokens TokenSaver, locker Locker, profile string, token credential.Token) error

CommitLogin 供 CLI 与桌面登录共用。浏览器交互不占锁,提交时重新核对 Profile。

func LockProfile added in v0.1.4

func LockProfile(ctx context.Context, locker Locker, profile string) (func() error, error)

LockProfile 统一所有凭据写操作的跨进程互斥;同时需要配置锁时先取得此锁。

func ValidateTokenSite added in v0.1.4

func ValidateTokenSite(token credential.Token, site string) error

ValidateTokenSite 在构造 API 请求前绑定凭据和站点,防止配置变更后发送旧站点的 Token。

Types

type ConfigLoader

type ConfigLoader interface {
	Load() (projectconfig.Config, error)
}

type CredentialLoader

type CredentialLoader interface {
	Load(profile string) (credential.Token, error)
}

type Locker

type Locker interface {
	Lock(ctx context.Context, key string) (unlock func() error, err error)
}

type LoginOptions

type LoginOptions struct {
	Manual    bool
	NoBrowser bool
}

type Manager

type Manager struct {
	Config        ConfigLoader
	Tokens        TokenRepository
	Locker        Locker
	Refresh       func(context.Context, credential.Token) (oauth.TokenResponse, error)
	Now           func() time.Time
	RefreshBefore time.Duration
}

func (Manager) EnsureFresh

func (m Manager) EnsureFresh(ctx context.Context, profile string) (credential.Token, error)

func (Manager) RefreshNow

func (m Manager) RefreshNow(ctx context.Context, profile string) (credential.Token, error)

func (Manager) Supervise

func (m Manager) Supervise(ctx context.Context, profile string, interval time.Duration, onError func(error))

Supervise refreshes credentials for future API requests. Its context belongs to the supervisor, not to an established SSH session, so a refresh failure is reported but never closes an active connection.

type ProfileSupervisor

type ProfileSupervisor struct {
	Config      ConfigLoader
	Credentials CredentialLoader
	Freshener   TokenFreshener
	Interval    time.Duration
	OnError     func(profile string, err error)
}

ProfileSupervisor 在应用存活期间持续检查所有已保存 Refresh Token 的 Profile。它每轮重新读取配置和凭据,因此运行期间新增、删除或重新登录的 Profile 不需要重启应用即可生效。

func (ProfileSupervisor) Run

func (s ProfileSupervisor) Run(ctx context.Context)

type Service

type Service struct {
	Config    ConfigLoader
	Tokens    TokenRepository
	Manager   Manager
	LoginFlow func(context.Context, string, LoginOptions) (credential.Token, error)
	// ManualLoginFlow 是其他程序占用私有协议或系统禁止注册协议时永久保留的回退方式。
	ManualLoginFlow func(context.Context, string, LoginOptions) (credential.Token, error)
	Revoke          func(context.Context, credential.Token) error
	Now             func() time.Time
	Timeout         time.Duration
}

func (Service) Login

func (s Service) Login(ctx context.Context, requestedProfile string, options LoginOptions) (Status, error)

func (Service) Logout

func (s Service) Logout(ctx context.Context, requestedProfile string) error

func (Service) Refresh

func (s Service) Refresh(ctx context.Context, requestedProfile string) (Status, error)

func (Service) Status

func (s Service) Status(requestedProfile string) (Status, error)

type Status

type Status struct {
	Profile          string
	LoggedIn         bool
	Expired          bool
	RefreshAvailable bool
	ExpiresAt        time.Time
}

type TokenFreshener

type TokenFreshener interface {
	EnsureFresh(context.Context, string) (credential.Token, error)
}

type TokenRepository

type TokenRepository interface {
	Load(profile string) (credential.Token, error)
	Save(profile string, token credential.Token) error
	Delete(profile string) error
}

type TokenSaver added in v0.1.4

type TokenSaver interface {
	Save(string, credential.Token) error
}

Jump to

Keyboard shortcuts

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