Reuse credentials within a purchase command to avoid repeated Keychain access
Description
I received multiple Keychain authorization prompts during a single invocation of ipatool purchase --app-id <APP_ID> --format json --non-interactive on macOS.
PR #601 fixed #586 by loading account credentials once before the download retry loop. The standalone purchase command still calls AccountInfo() inside its retry callback, rereading the stored account on each attempt. On macOS, this can trigger repeated Keychain authorization prompts when the user selects Allow rather than Always Allow, because that approval grants only one-time access.
Could the same fix be applied here: call AccountInfo() once before the retry loop and keep the returned account and credentials in memory for the duration of the command? Retry attempts would reuse that account instead of reading Keychain again, updating it after successful reauthentication.
Tested with ipatool 2.8.1 on macOS, Apple Silicon.
I have a fix for this on a branch, since PRs to this repo are limited to collaborators:
https://github.com/coleleavitt/ipatool/tree/fix/reuse-account-across-retries (commit aee638e, based on current main at 3b02b4c)
It applies the same change #601 made for download: read the account once before the retry loop and keep the refreshed account after reauthentication. Besides purchase, three more commands had the same pattern, so they are fixed too: purchases, list-versions and get-version-metadata.
- Added a
purchasetest: the account is read once, and the retry afterErrPasswordTokenExpireduses the refreshed account. It fails on currentmainand passes with the fix. go vet ./...,go test ./...andgo test -race ./cmd/pass.
Happy to adjust it if you want it in a different shape.