Modern Apps git

← xtool.git

gsa: more SMS 2FA fixes (#416)

Commit
2186b7238308d30b87e82d8fec824a37b7909c55
Author
Kabir Oberai <[email protected]>
When
2026-10-31 01:54 UTC (1 month ago)
Parents
90fe13f
## What does this PR do?

Applies the 2FA SMS login fixes from #405

## How was it tested?

- [x] 2FA SMS arrives
- [x] Can log in with SMS code

## AI tool usage

How much of the code in this PR was AI-assisted? (check one)

- [ ] **0** - No AI was used to write code
- [x] **1** - I was assisted by AI in writing code. I reviewed the
finished result.
- [ ] **2** - I set the AI going and left it to it; nobody has read the
result - no review, or AI review only

<!-- If an AI agent is filling this in: declare the level honestly, and
open as a draft if it is #2. Do not lower the declared level to get the
PR reviewed. -->


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Improvements**
* SMS verification requests now use an updated phone verification format
and numeric phone-number IDs.
* Code validation also uses numeric phone-number IDs, keeping the
identifier format consistent across SMS authentication steps. The
verification request and code-validation request now follow the same
updated format.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: Corne Steenhuis <[email protected]>

Diff

Sources/XKit/GrandSlam/Operations/GrandSlamTwoFactorAuthenticateOperation.swift
diff --git a/Sources/XKit/GrandSlam/Operations/GrandSlamTwoFactorAuthenticateOperation.swift b/Sources/XKit/GrandSlam/Operations/GrandSlamTwoFactorAuthenticateOperation.swiftindex 6fc7079..5a41e02 100644--- a/Sources/XKit/GrandSlam/Operations/GrandSlamTwoFactorAuthenticateOperation.swift+++ b/Sources/XKit/GrandSlam/Operations/GrandSlamTwoFactorAuthenticateOperation.swift@@ -27,7 +27,7 @@ struct GrandSlamTwoFactorAuthenticateOperation {      private func performSMSAuth() async throws {         // TODO: parse phone number list from o=complete req?-        let phoneNumberID = "1"+        let phoneNumberID = 1         do {             try await client.send(GrandSlamSMSAuthRequest(loginData: loginData, phoneNumberID: phoneNumberID))         } catch let error as HTTPResponseError where error.status.code == 403 {@@ -40,7 +40,7 @@ struct GrandSlamTwoFactorAuthenticateOperation {         try await validateCode(phoneNumberID: phoneNumberID)     } -    private func validateCode(phoneNumberID: String? = nil) async throws {+    private func validateCode(phoneNumberID: Int? = nil) async throws {         guard let code = await self.delegate.fetchCode() else { throw Error.userCancelled }         let request: any GrandSlamRequest = if let phoneNumberID {             GrandSlamValidateSMSRequest(
Sources/XKit/GrandSlam/Requests/Concrete/GrandSlamTrustedDeviceRequest.swift
diff --git a/Sources/XKit/GrandSlam/Requests/Concrete/GrandSlamTrustedDeviceRequest.swift b/Sources/XKit/GrandSlam/Requests/Concrete/GrandSlamTrustedDeviceRequest.swiftindex 1cf55c4..628ba9f 100644--- a/Sources/XKit/GrandSlam/Requests/Concrete/GrandSlamTrustedDeviceRequest.swift+++ b/Sources/XKit/GrandSlam/Requests/Concrete/GrandSlamTrustedDeviceRequest.swift@@ -35,16 +35,22 @@ struct GrandSlamSMSAuthRequest: GrandSlamTwoFactorRequest {         static func decode(data: Data) throws {}     } -    static let endpoint: GrandSlamEndpoint = .url(URL(string: "https://gsa.apple.com/auth/verify/phone/put?mode=sms")!)+    static let endpoint: GrandSlamEndpoint = .url(URL(string: "https://gsa.apple.com/auth/verify/phone")!)      let loginData: GrandSlamLoginData-    let phoneNumberID: String+    let phoneNumberID: Int++    var extraHeaders: [String: String] {+        [+            "Content-Type": "application/json",+            "Accept": "application/json",+        ]+    }      func content(anisetteData: AnisetteData) -> GrandSlamRequestContent {-        .post([-            "serverInfo": [-                "phoneNumber.id": phoneNumberID-            ],-        ])+        .put([+            "phoneNumber": ["id": phoneNumberID],+            "mode": "sms",+        ], type: .json)     } }
Sources/XKit/GrandSlam/Requests/Concrete/GrandSlamValidateRequest.swift
diff --git a/Sources/XKit/GrandSlam/Requests/Concrete/GrandSlamValidateRequest.swift b/Sources/XKit/GrandSlam/Requests/Concrete/GrandSlamValidateRequest.swiftindex 72a697a..b93c614 100644--- a/Sources/XKit/GrandSlam/Requests/Concrete/GrandSlamValidateRequest.swift+++ b/Sources/XKit/GrandSlam/Requests/Concrete/GrandSlamValidateRequest.swift@@ -29,20 +29,25 @@ struct GrandSlamValidateSMSRequest: GrandSlamTwoFactorRequest {     }      static let endpoint: GrandSlamEndpoint = .url(URL(-        string: "https://gsa.apple.com/auth/verify/phone/securitycode?referrer=/auth/verify/phone/put"+        string: "https://gsa.apple.com/auth/verify/phone/securitycode"     )!)      let loginData: GrandSlamLoginData-    let phoneNumberID: String+    let phoneNumberID: Int     let verificationCode: String +    var extraHeaders: [String: String] {+        [+            "Content-Type": "application/json",+            "Accept": "application/json",+        ]+    }+     func content(anisetteData: AnisetteData) -> GrandSlamRequestContent {         .post([-            "securityCode.code": verificationCode,-            "serverInfo": [-                "mode": "sms",-                "phoneNumber.id": phoneNumberID-            ]-        ])+            "securityCode": ["code": verificationCode],+            "phoneNumber": ["id": phoneNumberID],+            "mode": "sms",+        ], type: .json)     } }