Modern Apps git

← xtool.git

Improve GrandSlam auth error messages

Commit
79335148b04434367286a12e62e81cfb76aa5a34
Author
kabiroberai <[email protected]>
When
2021-02-03 22:40 UTC (5 years ago)
Parents
d8d5000

Diff

Supersign/GrandSlam/Operations/GrandSlamAuthenticateOperation.swift
diff --git a/Supersign/GrandSlam/Operations/GrandSlamAuthenticateOperation.swift b/Supersign/GrandSlam/Operations/GrandSlamAuthenticateOperation.swiftindex 8236b4e..37849b6 100644--- a/Supersign/GrandSlam/Operations/GrandSlamAuthenticateOperation.swift+++ b/Supersign/GrandSlam/Operations/GrandSlamAuthenticateOperation.swift@@ -10,11 +10,26 @@ import Foundation  class GrandSlamAuthenticateOperation { -    enum Error: Swift.Error {-        case failedChallenge-        case invalidSession-        case invalidResponse+    enum Error: Swift.Error, LocalizedError {+        case internalError         case failedSecondaryAuth++        var errorDescription: String? {+            switch self {+            case .internalError:+                return NSLocalizedString(+                    "apple_id_auth.error.internal",+                    value: "An internal authentication error occurred.",+                    comment: ""+                )+            case .failedSecondaryAuth:+                return NSLocalizedString(+                    "apple_id_auth.error.failed_secondary_auth",+                    value: "Could not complete 2-factor authentication.",+                    comment: ""+                )+            }+        }     }      private struct Response: Decodable {@@ -84,10 +99,10 @@ class GrandSlamAuthenticateOperation {         srpClient.add(string: "|")          guard srpClient.verify(hamk: completeResponse.hamk) && srpClient.verify(negProto: completeResponse.negProto)-            else { return completion(.failure(Error.invalidSession)) }+            else { return completion(.failure(Error.internalError)) }          guard let rawLoginResponse = srpClient.decrypt(cbc: completeResponse.encryptedResponse) else {-            return completion(.failure(Error.invalidResponse))+            return completion(.failure(Error.internalError))         }          let response: Response@@ -134,7 +149,7 @@ class GrandSlamAuthenticateOperation {             serverPublicKey: initResponse.serverPublicKey,             isS2K: isS2K         )-        guard let m1Data = mDataRaw else { return completion(.failure(Error.failedChallenge)) }+        guard let m1Data = mDataRaw else { return completion(.failure(Error.internalError)) }          let completeRequest = GrandSlamAuthCompleteRequest(             username: username, cookie: initResponse.cookie, m1Data: m1Data
Supersign/GrandSlam/Operations/GrandSlamTwoFactorAuthenticateOperation.swift
diff --git a/Supersign/GrandSlam/Operations/GrandSlamTwoFactorAuthenticateOperation.swift b/Supersign/GrandSlam/Operations/GrandSlamTwoFactorAuthenticateOperation.swiftindex fd96921..bd4fb17 100644--- a/Supersign/GrandSlam/Operations/GrandSlamTwoFactorAuthenticateOperation.swift+++ b/Supersign/GrandSlam/Operations/GrandSlamTwoFactorAuthenticateOperation.swift@@ -69,10 +69,9 @@ class GrandSlamTwoFactorAuthenticateOperation {     func perform(completion: @escaping (Result<(), Swift.Error>) -> Void) {         switch mode {         case .secondaryAuth:-            // TODO: Does this always work?-            // we *should* be calling performSecondaryAuth but that doesn't seem-            // to actually trigger the 2fa prompt on trusted devices. Somehow-            // using trustedDevice auth seems to work fine though+            // TODO: We *should* be calling performSecondaryAuth – it does+            // seem like performTrustedDeviceAuth sometimes works here but+            // other times re-authenticating continues to 409             self.performTrustedDeviceAuth(completion: completion)         case .trustedDeviceSecondaryAuth:             self.performTrustedDeviceAuth(completion: completion)