feat(auth): refresh API key during cookie authentication

This commit is contained in:
hkfires
2025-12-08 09:48:31 +08:00
parent 6cf1d8a947
commit e9eb4db8bb

View File

@@ -309,17 +309,23 @@ func (ia *IFlowAuth) AuthenticateWithCookie(ctx context.Context, cookie string)
return nil, fmt.Errorf("iflow cookie authentication: cookie is empty") return nil, fmt.Errorf("iflow cookie authentication: cookie is empty")
} }
// First, get initial API key information using GET request // First, get initial API key information using GET request to obtain the name
keyInfo, err := ia.fetchAPIKeyInfo(ctx, cookie) keyInfo, err := ia.fetchAPIKeyInfo(ctx, cookie)
if err != nil { if err != nil {
return nil, fmt.Errorf("iflow cookie authentication: fetch initial API key info failed: %w", err) return nil, fmt.Errorf("iflow cookie authentication: fetch initial API key info failed: %w", err)
} }
// Convert to token data format // Refresh the API key using POST request
refreshedKeyInfo, err := ia.RefreshAPIKey(ctx, cookie, keyInfo.Name)
if err != nil {
return nil, fmt.Errorf("iflow cookie authentication: refresh API key failed: %w", err)
}
// Convert to token data format using refreshed key
data := &IFlowTokenData{ data := &IFlowTokenData{
APIKey: keyInfo.APIKey, APIKey: refreshedKeyInfo.APIKey,
Expire: keyInfo.ExpireTime, Expire: refreshedKeyInfo.ExpireTime,
Email: keyInfo.Name, Email: refreshedKeyInfo.Name,
Cookie: cookie, Cookie: cookie,
} }