Skip to content

Commit 9576253

Browse files
authored
Merge pull request #265 from shelltime/fix/codex-auth-json-format
fix(daemon): update codex auth.json parsing to match actual file format
2 parents ac9f496 + bbb68b6 commit 9576253

1 file changed

Lines changed: 11 additions & 19 deletions

File tree

daemon/codex_ratelimit.go

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,16 @@ type codexAuthData struct {
5757

5858
// codexAuthJSON maps the full ~/.codex/auth.json structure
5959
type codexAuthJSON struct {
60-
AuthMode string `json:"authMode"`
61-
APIKey *string `json:"apiKey"`
62-
TokenData *codexAuthTokenData `json:"tokenData"`
60+
OpenAIAPIKey *string `json:"OPENAI_API_KEY"`
61+
Tokens *codexTokenData `json:"tokens"`
62+
LastRefresh string `json:"last_refresh"`
6363
}
6464

65-
type codexAuthTokenData struct {
66-
AccessToken string `json:"accessToken"`
67-
RefreshToken string `json:"refreshToken"`
68-
IDTokenClaims *codexIDTokenClaims `json:"idTokenClaims"`
69-
}
70-
71-
type codexIDTokenClaims struct {
72-
AccountID string `json:"accountId"`
65+
type codexTokenData struct {
66+
IDToken string `json:"id_token"`
67+
AccessToken string `json:"access_token"`
68+
RefreshToken string `json:"refresh_token"`
69+
AccountID string `json:"account_id"`
7370
}
7471

7572
func codexConfigDirPath() (string, error) {
@@ -153,18 +150,13 @@ func loadCodexAuth() (*codexAuthData, error) {
153150
return nil, fmt.Errorf("failed to parse codex auth JSON: %w", err)
154151
}
155152

156-
if auth.TokenData == nil || auth.TokenData.AccessToken == "" {
153+
if auth.Tokens == nil || auth.Tokens.AccessToken == "" {
157154
return nil, errCodexAuthInvalid
158155
}
159156

160-
accountID := ""
161-
if auth.TokenData.IDTokenClaims != nil {
162-
accountID = auth.TokenData.IDTokenClaims.AccountID
163-
}
164-
165157
return &codexAuthData{
166-
AccessToken: auth.TokenData.AccessToken,
167-
AccountID: accountID,
158+
AccessToken: auth.Tokens.AccessToken,
159+
AccountID: auth.Tokens.AccountID,
168160
}, nil
169161
}
170162

0 commit comments

Comments
 (0)