refactor(auth): remove unused Refresh methods from authenticators
- Deleted `Refresh` implementations in Codex, Claude, Gemini, Qwen, and Gemini-web authenticators. - Updated the `Authenticator` interface to exclude `Refresh` for cleaner design. - Revised `Manager` and related components to handle refresh logic improvements. - Simplified token refresh behavior and eliminated redundant code paths.
This commit is contained in:
@@ -143,36 +143,3 @@ func (a *ClaudeAuthenticator) Login(ctx context.Context, cfg *config.Config, opt
|
||||
Metadata: metadata,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (a *ClaudeAuthenticator) Refresh(ctx context.Context, cfg *config.Config, record *TokenRecord) (*TokenRecord, error) {
|
||||
if record == nil || record.Storage == nil {
|
||||
return nil, fmt.Errorf("cliproxy auth: empty token record for claude refresh")
|
||||
}
|
||||
if cfg == nil {
|
||||
return nil, fmt.Errorf("cliproxy auth: configuration is required")
|
||||
}
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
|
||||
storage, ok := record.Storage.(*claude.ClaudeTokenStorage)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cliproxy auth: unexpected token storage type for claude refresh")
|
||||
}
|
||||
|
||||
// Refresh via auth service directly (no legacy client)
|
||||
svc := claude.NewClaudeAuth(cfg)
|
||||
td, err := svc.RefreshTokensWithRetry(ctx, storage.RefreshToken, 3)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
svc.UpdateTokenStorage(storage, td)
|
||||
|
||||
result := &TokenRecord{
|
||||
Provider: a.Provider(),
|
||||
FileName: record.FileName,
|
||||
Storage: storage,
|
||||
Metadata: record.Metadata,
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -142,35 +142,3 @@ func (a *CodexAuthenticator) Login(ctx context.Context, cfg *config.Config, opts
|
||||
Metadata: metadata,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (a *CodexAuthenticator) Refresh(ctx context.Context, cfg *config.Config, record *TokenRecord) (*TokenRecord, error) {
|
||||
if record == nil || record.Storage == nil {
|
||||
return nil, fmt.Errorf("cliproxy auth: empty token record for codex refresh")
|
||||
}
|
||||
if cfg == nil {
|
||||
return nil, fmt.Errorf("cliproxy auth: configuration is required")
|
||||
}
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
|
||||
storage, ok := record.Storage.(*codex.CodexTokenStorage)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cliproxy auth: unexpected token storage type for codex refresh")
|
||||
}
|
||||
|
||||
svc := codex.NewCodexAuth(cfg)
|
||||
td, err := svc.RefreshTokensWithRetry(ctx, storage.RefreshToken, 3)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
svc.UpdateTokenStorage(storage, td)
|
||||
|
||||
result := &TokenRecord{
|
||||
Provider: a.Provider(),
|
||||
FileName: record.FileName,
|
||||
Storage: storage,
|
||||
Metadata: record.Metadata,
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -23,13 +23,6 @@ func (a *GeminiWebAuthenticator) Login(ctx context.Context, cfg *config.Config,
|
||||
return nil, fmt.Errorf("gemini-web authenticator does not support scripted login; use CLI --gemini-web-auth")
|
||||
}
|
||||
|
||||
func (a *GeminiWebAuthenticator) Refresh(ctx context.Context, cfg *config.Config, record *TokenRecord) (*TokenRecord, error) {
|
||||
_ = ctx
|
||||
_ = cfg
|
||||
_ = record
|
||||
return nil, ErrRefreshNotSupported
|
||||
}
|
||||
|
||||
func (a *GeminiWebAuthenticator) RefreshLead() *time.Duration {
|
||||
d := 9 * time.Minute
|
||||
return &d
|
||||
|
||||
@@ -66,7 +66,3 @@ func (a *GeminiAuthenticator) Login(ctx context.Context, cfg *config.Config, opt
|
||||
Metadata: metadata,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (a *GeminiAuthenticator) Refresh(ctx context.Context, cfg *config.Config, record *TokenRecord) (*TokenRecord, error) {
|
||||
return nil, ErrRefreshNotSupported
|
||||
}
|
||||
|
||||
@@ -37,6 +37,5 @@ type TokenStore interface {
|
||||
type Authenticator interface {
|
||||
Provider() string
|
||||
Login(ctx context.Context, cfg *config.Config, opts *LoginOptions) (*TokenRecord, error)
|
||||
Refresh(ctx context.Context, cfg *config.Config, record *TokenRecord) (*TokenRecord, error)
|
||||
RefreshLead() *time.Duration
|
||||
}
|
||||
|
||||
@@ -67,29 +67,3 @@ func (m *Manager) Login(ctx context.Context, provider string, cfg *config.Config
|
||||
}
|
||||
return record, savedPath, nil
|
||||
}
|
||||
|
||||
// Refresh delegates to the provider-specific refresh implementation and persists the result.
|
||||
func (m *Manager) Refresh(ctx context.Context, provider string, cfg *config.Config, record *TokenRecord) (*TokenRecord, string, error) {
|
||||
auth, ok := m.authenticators[provider]
|
||||
if !ok {
|
||||
return nil, "", fmt.Errorf("cliproxy auth: authenticator %s not registered", provider)
|
||||
}
|
||||
|
||||
updated, err := auth.Refresh(ctx, cfg, record)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
if updated == nil {
|
||||
updated = record
|
||||
}
|
||||
|
||||
if m.store == nil {
|
||||
return updated, "", nil
|
||||
}
|
||||
|
||||
savedPath, err := m.store.Save(ctx, cfg, updated)
|
||||
if err != nil {
|
||||
return updated, "", err
|
||||
}
|
||||
return updated, savedPath, nil
|
||||
}
|
||||
|
||||
@@ -110,38 +110,3 @@ func (a *QwenAuthenticator) Login(ctx context.Context, cfg *config.Config, opts
|
||||
Metadata: metadata,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (a *QwenAuthenticator) Refresh(ctx context.Context, cfg *config.Config, record *TokenRecord) (*TokenRecord, error) {
|
||||
if record == nil || record.Storage == nil {
|
||||
return nil, fmt.Errorf("cliproxy auth: empty token record for qwen refresh")
|
||||
}
|
||||
if cfg == nil {
|
||||
return nil, fmt.Errorf("cliproxy auth: configuration is required")
|
||||
}
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
|
||||
storage, ok := record.Storage.(*qwen.QwenTokenStorage)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("cliproxy auth: unexpected token storage type for qwen refresh")
|
||||
}
|
||||
|
||||
svc := qwen.NewQwenAuth(cfg)
|
||||
td, err := svc.RefreshTokens(ctx, storage.RefreshToken)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
storage.AccessToken = td.AccessToken
|
||||
storage.RefreshToken = td.RefreshToken
|
||||
storage.ResourceURL = td.ResourceURL
|
||||
storage.Expire = td.Expire
|
||||
|
||||
result := &TokenRecord{
|
||||
Provider: a.Provider(),
|
||||
FileName: record.FileName,
|
||||
Storage: storage,
|
||||
Metadata: record.Metadata,
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user