feat(auth): hash account ID for improved uniqueness in credential filenames

This commit is contained in:
Luis Pater
2026-01-20 11:37:52 +08:00
parent 059bfee91b
commit 9823dc35e1

View File

@@ -3,6 +3,8 @@ package management
import ( import (
"bytes" "bytes"
"context" "context"
"crypto/sha256"
"encoding/hex"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
@@ -1389,6 +1391,11 @@ func (h *Handler) RequestCodexToken(c *gin.Context) {
accountID = claims.GetAccountID() accountID = claims.GetAccountID()
planType = strings.TrimSpace(claims.CodexAuthInfo.ChatgptPlanType) planType = strings.TrimSpace(claims.CodexAuthInfo.ChatgptPlanType)
} }
hashAccountID := ""
if accountID != "" {
digest := sha256.Sum256([]byte(accountID))
hashAccountID = hex.EncodeToString(digest[:])[:8]
}
// Build bundle compatible with existing storage // Build bundle compatible with existing storage
bundle := &codex.CodexAuthBundle{ bundle := &codex.CodexAuthBundle{
TokenData: codex.CodexTokenData{ TokenData: codex.CodexTokenData{
@@ -1404,7 +1411,7 @@ func (h *Handler) RequestCodexToken(c *gin.Context) {
// Create token storage and persist // Create token storage and persist
tokenStorage := openaiAuth.CreateTokenStorage(bundle) tokenStorage := openaiAuth.CreateTokenStorage(bundle)
fileName := codex.CredentialFileName(tokenStorage.Email, planType, true) fileName := codex.CredentialFileName(tokenStorage.Email, planType, hashAccountID, true)
record := &coreauth.Auth{ record := &coreauth.Auth{
ID: fileName, ID: fileName,
Provider: "codex", Provider: "codex",