mirror of
https://github.com/Finesssee/ProxyPilot.git
synced 2026-11-19 02:17:46 +00:00
feat(auth): add hashed account ID to credential filenames for team plans
- Extract plan type and account ID from Codex JWT token
- Include first 8 chars of SHA-256 hashed account ID in filename for team plans
- Helps disambiguate multiple team accounts with the same email
- Filename format: codex-{hash}-{email}-team.json
This commit is contained in:
+43
-1
@@ -2,6 +2,8 @@ package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -186,7 +188,22 @@ waitForCallback:
|
||||
return nil, fmt.Errorf("codex token storage missing account information")
|
||||
}
|
||||
|
||||
fileName := fmt.Sprintf("codex-%s.json", tokenStorage.Email)
|
||||
// Extract plan type and account ID for filename disambiguation
|
||||
planType := ""
|
||||
hashAccountID := ""
|
||||
if tokenStorage.IDToken != "" {
|
||||
if claims, errParse := codex.ParseJWTToken(tokenStorage.IDToken); errParse == nil && claims != nil {
|
||||
planType = strings.TrimSpace(claims.CodexAuthInfo.ChatgptPlanType)
|
||||
accountID := strings.TrimSpace(claims.CodexAuthInfo.ChatgptAccountID)
|
||||
if accountID != "" {
|
||||
digest := sha256.Sum256([]byte(accountID))
|
||||
hashAccountID = hex.EncodeToString(digest[:])[:8]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Generate filename with plan type and hashed account ID for team plans
|
||||
fileName := codexCredentialFileName(tokenStorage.Email, planType, hashAccountID)
|
||||
metadata := map[string]any{
|
||||
"email": tokenStorage.Email,
|
||||
}
|
||||
@@ -204,3 +221,28 @@ waitForCallback:
|
||||
Metadata: metadata,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// codexCredentialFileName generates the filename for Codex credential storage.
|
||||
// For team plans, it includes a hashed account ID to disambiguate multiple accounts.
|
||||
func codexCredentialFileName(email, planType, hashAccountID string) string {
|
||||
email = strings.TrimSpace(email)
|
||||
plan := normalizePlanTypeForFilename(planType)
|
||||
|
||||
if plan == "" {
|
||||
return fmt.Sprintf("codex-%s.json", email)
|
||||
} else if plan == "team" && hashAccountID != "" {
|
||||
return fmt.Sprintf("codex-%s-%s-%s.json", hashAccountID, email, plan)
|
||||
}
|
||||
return fmt.Sprintf("codex-%s-%s.json", email, plan)
|
||||
}
|
||||
|
||||
// normalizePlanTypeForFilename converts plan types to filename-safe values.
|
||||
func normalizePlanTypeForFilename(planType string) string {
|
||||
planType = strings.ToLower(strings.TrimSpace(planType))
|
||||
switch planType {
|
||||
case "plus", "team", "enterprise":
|
||||
return planType
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user