-
Notifications
You must be signed in to change notification settings - Fork 0
fix(daemon): update codex auth.json parsing to match actual file format #265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,19 +57,16 @@ type codexAuthData struct { | |
|
|
||
| // codexAuthJSON maps the full ~/.codex/auth.json structure | ||
| type codexAuthJSON struct { | ||
| AuthMode string `json:"authMode"` | ||
| APIKey *string `json:"apiKey"` | ||
| TokenData *codexAuthTokenData `json:"tokenData"` | ||
| OpenAIAPIKey *string `json:"OPENAI_API_KEY"` | ||
| Tokens *codexTokenData `json:"tokens"` | ||
| LastRefresh string `json:"last_refresh"` | ||
| } | ||
|
|
||
| type codexAuthTokenData struct { | ||
| AccessToken string `json:"accessToken"` | ||
| RefreshToken string `json:"refreshToken"` | ||
| IDTokenClaims *codexIDTokenClaims `json:"idTokenClaims"` | ||
| } | ||
|
|
||
| type codexIDTokenClaims struct { | ||
| AccountID string `json:"accountId"` | ||
| type codexTokenData struct { | ||
| IDToken string `json:"id_token"` | ||
| AccessToken string `json:"access_token"` | ||
| RefreshToken string `json:"refresh_token"` | ||
| AccountID string `json:"account_id"` | ||
| } | ||
|
|
||
| func codexConfigDirPath() (string, error) { | ||
|
|
@@ -153,18 +150,13 @@ func loadCodexAuth() (*codexAuthData, error) { | |
| return nil, fmt.Errorf("failed to parse codex auth JSON: %w", err) | ||
| } | ||
|
|
||
| if auth.TokenData == nil || auth.TokenData.AccessToken == "" { | ||
| if auth.Tokens == nil || auth.Tokens.AccessToken == "" { | ||
| return nil, errCodexAuthInvalid | ||
| } | ||
|
|
||
| accountID := "" | ||
| if auth.TokenData.IDTokenClaims != nil { | ||
| accountID = auth.TokenData.IDTokenClaims.AccountID | ||
| } | ||
|
|
||
| return &codexAuthData{ | ||
| AccessToken: auth.TokenData.AccessToken, | ||
| AccountID: accountID, | ||
| AccessToken: auth.Tokens.AccessToken, | ||
| AccountID: auth.Tokens.AccountID, | ||
| }, nil | ||
|
Comment on lines
+153
to
160
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation returns if auth.Tokens != nil && auth.Tokens.AccessToken != "" {
return &codexAuthData{
AccessToken: auth.Tokens.AccessToken,
AccountID: auth.Tokens.AccountID,
}, nil
}
if auth.OpenAIAPIKey != nil && *auth.OpenAIAPIKey != "" {
return &codexAuthData{
AccessToken: *auth.OpenAIAPIKey,
AccountID: "",
}, nil
}
return nil, errCodexAuthInvalid |
||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
LastRefreshfield is currently unused and itsstringtype is a potential point of failure if the JSON value is a number (e.g., a Unix timestamp), which is common for such fields. Similarly,IDTokenandRefreshTokenincodexTokenDataare unused. It is generally safer to omit unused fields to make the parsing more robust against format changes or unexpected types.