mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-02 20:40:52 +08:00
feat(auth): hash account ID for improved uniqueness in credential filenames
This commit is contained in:
@@ -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",
|
||||||
|
|||||||
Reference in New Issue
Block a user