From 9c1fe4d63b8a4856c6e0ba52f21a09c124cab8b7 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Wed, 25 May 2022 16:45:27 -0700 Subject: [PATCH] =?UTF-8?q?Fixes=20authenticating=20with=20old=20email=20a?= =?UTF-8?q?ddress=20after=20changing=20Apple=20ID=E2=80=99s=20primary=20em?= =?UTF-8?q?ail?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AltStore/Operations/AuthenticationOperation.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/AltStore/Operations/AuthenticationOperation.swift b/AltStore/Operations/AuthenticationOperation.swift index 6c717ea9..1aaf81bd 100644 --- a/AltStore/Operations/AuthenticationOperation.swift +++ b/AltStore/Operations/AuthenticationOperation.swift @@ -49,6 +49,7 @@ class AuthenticationOperation: ResultOperation<(ALTTeam, ALTCertificate, ALTAppl private lazy var storyboard = UIStoryboard(name: "Authentication", bundle: nil) + private var appleIDEmailAddress: String? private var appleIDPassword: String? private var shouldShowInstructions = false @@ -174,6 +175,13 @@ class AuthenticationOperation: ResultOperation<(ALTTeam, ALTCertificate, ALTAppl } account.update(account: altTeam.account) + + if let providedEmailAddress = self.appleIDEmailAddress + { + // Save the user's provided email address instead of the one associated with their account (which may be outdated). + account.appleID = providedEmailAddress + } + team.update(team: altTeam) try context.save() @@ -242,7 +250,7 @@ class AuthenticationOperation: ResultOperation<(ALTTeam, ALTCertificate, ALTAppl try context.save() // Update keychain - Keychain.shared.appleIDEmailAddress = altTeam.account.appleID + Keychain.shared.appleIDEmailAddress = self.appleIDEmailAddress ?? altTeam.account.appleID // Prefer the user's provided email address over the one associated with their account (which may be outdated). Keychain.shared.appleIDPassword = self.appleIDPassword Keychain.shared.signingCertificate = altCertificate.p12Data() @@ -359,6 +367,8 @@ private extension AuthenticationOperation func authenticate(appleID: String, password: String, completionHandler: @escaping (Result<(ALTAccount, ALTAppleAPISession), Swift.Error>) -> Void) { + self.appleIDEmailAddress = appleID + let fetchAnisetteDataOperation = FetchAnisetteDataOperation(context: self.context) fetchAnisetteDataOperation.resultHandler = { (result) in switch result