mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
feat(auth): refresh API key during cookie authentication
This commit is contained in:
@@ -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,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user