(authSvc *codex.CodexAuth, authBundle *codex.CodexAuthBundle)
| 252 | } |
| 253 | |
| 254 | func (a *CodexAuthenticator) buildAuthRecord(authSvc *codex.CodexAuth, authBundle *codex.CodexAuthBundle) (*coreauth.Auth, error) { |
| 255 | tokenStorage := authSvc.CreateTokenStorage(authBundle) |
| 256 | |
| 257 | if tokenStorage == nil || tokenStorage.Email == "" { |
| 258 | return nil, fmt.Errorf("codex token storage missing account information") |
| 259 | } |
| 260 | |
| 261 | planType := "" |
| 262 | hashAccountID := "" |
| 263 | if tokenStorage.IDToken != "" { |
| 264 | if claims, errParse := codex.ParseJWTToken(tokenStorage.IDToken); errParse == nil && claims != nil { |
| 265 | planType = strings.TrimSpace(claims.CodexAuthInfo.ChatgptPlanType) |
| 266 | accountID := strings.TrimSpace(claims.CodexAuthInfo.ChatgptAccountID) |
| 267 | if accountID != "" { |
| 268 | digest := sha256.Sum256([]byte(accountID)) |
| 269 | hashAccountID = hex.EncodeToString(digest[:])[:8] |
| 270 | } |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | fileName := codex.CredentialFileName(tokenStorage.Email, planType, hashAccountID, true) |
| 275 | metadata := map[string]any{ |
| 276 | "email": tokenStorage.Email, |
| 277 | } |
| 278 | |
| 279 | fmt.Println("Codex authentication successful") |
| 280 | if authBundle.APIKey != "" { |
| 281 | fmt.Println("Codex API key obtained and stored") |
| 282 | } |
| 283 | |
| 284 | return &coreauth.Auth{ |
| 285 | ID: fileName, |
| 286 | Provider: a.Provider(), |
| 287 | FileName: fileName, |
| 288 | Storage: tokenStorage, |
| 289 | Metadata: metadata, |
| 290 | Attributes: map[string]string{ |
| 291 | "plan_type": planType, |
| 292 | }, |
| 293 | }, nil |
| 294 | } |
no test coverage detected