MCPcopy Create free account
hub / github.com/diillson/chatcli / syncCodexCliCreds

Function syncCodexCliCreds

auth/cli_sync.go:78–118  ·  view source on GitHub ↗

syncCodexCliCreds syncs credentials from OpenAI Codex CLI (~/.codex/).

(logger *zap.Logger)

Source from the content-addressed store, hash-verified

76
77// syncCodexCliCreds syncs credentials from OpenAI Codex CLI (~/.codex/).
78func syncCodexCliCreds(logger *zap.Logger) bool {
79 home, err := os.UserHomeDir()
80 if err != nil {
81 return false
82 }
83
84 paths := []string{
85 filepath.Join(home, ".codex", "credentials.json"),
86 filepath.Join(home, ".codex", "auth.json"),
87 }
88
89 for _, path := range paths {
90 data, err := os.ReadFile(path) //#nosec G304 -- path supplied by user/agent through validated tool surface (boundary check upstream)
91 if err != nil {
92 continue
93 }
94
95 cred := parseCodexCredentials(data, logger)
96 if cred == nil {
97 continue
98 }
99
100 store := LoadStore(logger)
101 existing := store.Profiles["openai-codex-sync"]
102 if existing != nil && existing.Expires > cred.Expires {
103 logger.Debug(i18n.T("auth.sync.codex_newer"))
104 return false
105 }
106
107 if err := UpsertProfile("openai-codex-sync", cred, logger); err != nil {
108 logger.Warn(i18n.T("auth.sync.codex_save_failed"), zap.Error(err))
109 return false
110 }
111
112 logger.Info(i18n.T("auth.sync.codex_synced"),
113 zap.String("source", path))
114 return true
115 }
116
117 return false
118}
119
120// parseClaudeCredentials parses Claude Code credential formats.
121func parseClaudeCredentials(data []byte, logger *zap.Logger) *AuthProfileCredential {

Callers 1

SyncExternalCliCredsFunction · 0.85

Calls 8

TFunction · 0.92
parseCodexCredentialsFunction · 0.85
LoadStoreFunction · 0.85
UpsertProfileFunction · 0.85
WarnMethod · 0.80
ErrorMethod · 0.65
InfoMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected