syncClaudeCodeCreds syncs credentials from Claude Code (~/.claude/).
(logger *zap.Logger)
| 31 | |
| 32 | // syncClaudeCodeCreds syncs credentials from Claude Code (~/.claude/). |
| 33 | func syncClaudeCodeCreds(logger *zap.Logger) bool { |
| 34 | home, err := os.UserHomeDir() |
| 35 | if err != nil { |
| 36 | return false |
| 37 | } |
| 38 | |
| 39 | // Try multiple known locations |
| 40 | paths := []string{ |
| 41 | filepath.Join(home, ".claude", "credentials.json"), |
| 42 | filepath.Join(home, ".claude.json"), |
| 43 | } |
| 44 | |
| 45 | for _, path := range paths { |
| 46 | data, err := os.ReadFile(path) //#nosec G304 -- path supplied by user/agent through validated tool surface (boundary check upstream) |
| 47 | if err != nil { |
| 48 | continue |
| 49 | } |
| 50 | |
| 51 | cred := parseClaudeCredentials(data, logger) |
| 52 | if cred == nil { |
| 53 | continue |
| 54 | } |
| 55 | |
| 56 | // Check if we already have fresher credentials |
| 57 | store := LoadStore(logger) |
| 58 | existing := store.Profiles["anthropic-oauth-sync"] |
| 59 | if existing != nil && existing.Expires > cred.Expires { |
| 60 | logger.Debug(i18n.T("auth.sync.anthropic_newer")) |
| 61 | return false |
| 62 | } |
| 63 | |
| 64 | if err := UpsertProfile("anthropic-oauth-sync", cred, logger); err != nil { |
| 65 | logger.Warn(i18n.T("auth.sync.anthropic_save_failed"), zap.Error(err)) |
| 66 | return false |
| 67 | } |
| 68 | |
| 69 | logger.Info(i18n.T("auth.sync.anthropic_synced"), |
| 70 | zap.String("source", path)) |
| 71 | return true |
| 72 | } |
| 73 | |
| 74 | return false |
| 75 | } |
| 76 | |
| 77 | // syncCodexCliCreds syncs credentials from OpenAI Codex CLI (~/.codex/). |
| 78 | func syncCodexCliCreds(logger *zap.Logger) bool { |
no test coverage detected