From fb809edc28e809aba8a17aaf3e1c4b37086d9cd4 Mon Sep 17 00:00:00 2001 From: Michal Smaga Date: Thu, 12 Dec 2024 13:10:13 +0100 Subject: [PATCH 1/2] Ensure authToken is present before calling refreshAuthTokenIfNeeded --- .../Flows/AppStore/AppStoreAccountManagementFlow.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Sources/Subscription/Flows/AppStore/AppStoreAccountManagementFlow.swift b/Sources/Subscription/Flows/AppStore/AppStoreAccountManagementFlow.swift index bb955ccde..ff75ecf4b 100644 --- a/Sources/Subscription/Flows/AppStore/AppStoreAccountManagementFlow.swift +++ b/Sources/Subscription/Flows/AppStore/AppStoreAccountManagementFlow.swift @@ -23,6 +23,7 @@ import os.log public enum AppStoreAccountManagementFlowError: Swift.Error { case noPastTransaction case authenticatingWithTransactionFailed + case missingAuthTokenOnRefresh } @available(macOS 12.0, iOS 15.0, *) @@ -46,7 +47,8 @@ public final class DefaultAppStoreAccountManagementFlow: AppStoreAccountManageme @discardableResult public func refreshAuthTokenIfNeeded() async -> Result { Logger.subscription.info("[AppStoreAccountManagementFlow] refreshAuthTokenIfNeeded") - var authToken = accountManager.authToken ?? "" + + guard let authToken = accountManager.authToken else { return .failure(.missingAuthTokenOnRefresh) } // Check if auth token if still valid if case let .failure(validateTokenError) = await authEndpointService.validateToken(accessToken: authToken) { @@ -58,8 +60,9 @@ public final class DefaultAppStoreAccountManagementFlow: AppStoreAccountManageme switch await authEndpointService.storeLogin(signature: lastTransactionJWSRepresentation) { case .success(let response): if response.externalID == accountManager.externalID { - authToken = response.authToken - accountManager.storeAuthToken(token: authToken) + let refreshedAuthToken = response.authToken + accountManager.storeAuthToken(token: refreshedAuthToken) + return .success(refreshedAuthToken) } case .failure(let storeLoginError): Logger.subscription.error("[AppStoreAccountManagementFlow] storeLogin error: \(String(reflecting: storeLoginError), privacy: .public)") From 276754fc1efab85c39a77da64e68439e7f105de3 Mon Sep 17 00:00:00 2001 From: Michal Smaga Date: Thu, 12 Dec 2024 13:41:31 +0100 Subject: [PATCH 2/2] Add 'locale' to report broken site params --- Sources/PrivacyDashboard/PrivacyDashboardUserScript.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/PrivacyDashboard/PrivacyDashboardUserScript.swift b/Sources/PrivacyDashboard/PrivacyDashboardUserScript.swift index effe229fa..3fc35c46d 100644 --- a/Sources/PrivacyDashboard/PrivacyDashboardUserScript.swift +++ b/Sources/PrivacyDashboard/PrivacyDashboardUserScript.swift @@ -363,6 +363,7 @@ final class PrivacyDashboardUserScript: NSObject, StaticUserScript { {"id": "jsPerformance"}, {"id": "openerContext"}, {"id": "userRefreshCount"}, + {"id": "locale"}, ] } window.onGetToggleReportOptionsResponse(json);