Skip to content

Instantly share code, notes, and snippets.

@edinnen
Last active February 14, 2024 13:22
Show Gist options
  • Save edinnen/6b5388c54298d6f8d83f67cc2c3db2a4 to your computer and use it in GitHub Desktop.
Save edinnen/6b5388c54298d6f8d83f67cc2c3db2a4 to your computer and use it in GitHub Desktop.
Generate transfer_subs from a list of apple_user_ids
#!/bin/bash
totalLines=0
requestTransfer() {
transferSub=$(curl -sS --request POST $1 \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header "Authorization: Bearer $2" \
-d "sub=$3&target=$4&client_id=$5&client_secret=$6" \
| jq -r '.transfer_sub')
printf '%s,%s,%s,%s\n' "$7" "$8" "$9" "$transferSub"
}
generateTransferIdFunc() {
APIURL="https://appleid.apple.com/auth/usermigrationinfo"
recipientTeamId=THE_RECIPIENT_TEAM_ID
senderAppBundleID=YOUR_APP_BUNDLE_ID
senderSecret=YOUR_SENDER_SECRET
bearerAuth=$(curl -sS --request POST 'https://appleid.apple.com/auth/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'scope=user.migration' \
--data-urlencode "client_id=$senderAppBundleID" \
--data-urlencode "client_secret=$senderSecret" \
| jq -r '.access_token')
i=0
if [ $# -eq 1 ] && [ -f $1 ]
then
OLDIFS=$IFS
IFS=","
header=0
while read id guid userid email
do
if [ $header -eq 0 ]
then
header=1
printf "qxmd_id,guid,email,transfer_sub\n" > transfers.csv
continue
else
requestTransfer $APIURL $bearerAuth $userid $recipientTeamId $senderAppBundleID $senderSecret $id $guid $email &
((i=i+1))
if [ $i -eq 100 ]
then
sleep 1
i=0
fi
fi
done < $1 | pv -pt -s$totalLines >> transfers.csv
IFS=$OLDIFS
else
echo "Input file not found!"
fi
}
if [ $# -eq 1 ] && [ -f $1 ]
then
totalLines=$(< "$1" wc -l)
generateTransferIdFunc $1
else
echo "Input file not found!"
fi
@lslv1243
Copy link

Hi Ethan - Thanks for sharing this code.
My team is currently in the same process and I was wondering whether you can help us with a question. When does the old private/relay email stops working? Is it as soon as we transfer the app or only after we generate the new information in the receiving account?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment