Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Subscription oauth v2 #3480

Closed
wants to merge 65 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
cc16889
builds
federicocappelli Oct 16, 2024
8b07ea5
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Oct 16, 2024
79faa6b
auth and first purchase improved
federicocappelli Oct 21, 2024
44e00ee
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Oct 21, 2024
c6c2bef
purchase flow fixed
federicocappelli Oct 22, 2024
c640a91
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Oct 22, 2024
018751a
purchase fixed
federicocappelli Oct 23, 2024
de81314
token fixes
federicocappelli Oct 23, 2024
b4c661e
loggers improved and restore fixed
federicocappelli Oct 24, 2024
d123038
subscription refresh improved
federicocappelli Oct 25, 2024
9d90ccf
v1 to v2 auth migration
federicocappelli Oct 25, 2024
457922c
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Oct 25, 2024
60d4012
lint ad restore commented code
federicocappelli Oct 25, 2024
07e2cc0
review suggestions applied
federicocappelli Oct 29, 2024
bd5bb1b
tests and logs
federicocappelli Oct 30, 2024
e92d0db
vpn fixed
federicocappelli Oct 31, 2024
1406315
debug menu improved
federicocappelli Oct 31, 2024
eebbc48
unit tests and lint
federicocappelli Oct 31, 2024
8ea3254
unit tests and improvements
federicocappelli Nov 1, 2024
c78a9c2
signout as async
federicocappelli Nov 1, 2024
c021b95
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Nov 4, 2024
0f426a1
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Nov 4, 2024
f06370b
lint
federicocappelli Nov 5, 2024
5f69e54
BSK points to branch now
federicocappelli Nov 5, 2024
929e12d
bsk updated
federicocappelli Nov 5, 2024
386fd70
Merge branch 'main' of https://github.com/duckduckgo/iOS into fcappel…
federicocappelli Nov 6, 2024
b018cce
bsk local
federicocappelli Nov 7, 2024
00e55c5
Merge branch 'main' of https://github.com/duckduckgo/iOS into fcappel…
federicocappelli Nov 7, 2024
a955a78
BSK
federicocappelli Nov 7, 2024
b67e5d4
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Nov 7, 2024
47ac372
BSK update
federicocappelli Nov 8, 2024
80be4fe
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Nov 14, 2024
bd51e3f
DI improved
federicocappelli Nov 19, 2024
7327d2d
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Nov 19, 2024
67d5d50
token v1/v2 exchange fixed, token providing improved
federicocappelli Nov 22, 2024
d0c8344
updates after mac integration
federicocappelli Nov 27, 2024
60bad87
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Nov 27, 2024
170ed9e
merge
federicocappelli Nov 27, 2024
32e5de6
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Nov 27, 2024
87455ba
local bsk
federicocappelli Nov 27, 2024
0191b02
project fix
federicocappelli Nov 27, 2024
bd5cb7c
unit tests builds
federicocappelli Nov 28, 2024
f229b65
main merge
federicocappelli Nov 29, 2024
e4fbf00
BSK > branch
federicocappelli Nov 29, 2024
f8eabd5
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Nov 29, 2024
a745b49
packages
federicocappelli Nov 29, 2024
b3482bd
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Dec 2, 2024
464e598
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Dec 2, 2024
ba4cbad
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Dec 12, 2024
edf1bfa
updates from mac and unit tests fixed
federicocappelli Dec 12, 2024
88cd2d9
testing comments fixed
federicocappelli Jan 6, 2025
7b93366
BSK updated
federicocappelli Jan 7, 2025
e4dfc38
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Jan 8, 2025
0053c73
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Jan 9, 2025
62bd2da
BSK updated, some flows updated
federicocappelli Jan 10, 2025
b72a122
subscription manager load initial data improved, pixels added
federicocappelli Jan 12, 2025
4e887d4
BSK update with subscription cache bug fix
federicocappelli Jan 13, 2025
6f3a7ad
settings and init improvements
federicocappelli Jan 16, 2025
7a0e848
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Jan 16, 2025
ef81d09
Subscription stuff renamed
federicocappelli Jan 20, 2025
b4196db
BSK updated
federicocappelli Jan 20, 2025
bc33fcf
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Jan 20, 2025
5660c74
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Jan 20, 2025
5f574f3
Merge branch 'main' into fcappelli/subscription_oauth_api_v2
federicocappelli Jan 21, 2025
d045cce
pr suggestions
federicocappelli Jan 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
subscription manager load initial data improved, pixels added
  • Loading branch information
federicocappelli committed Jan 12, 2025
commit b72a122a526075e76cb2a387bc02bf10941e92db
4 changes: 4 additions & 0 deletions Core/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,8 @@ extension Pixel {
case privacyProSubscriptionCookieRefreshedWithEmptyValue
case privacyProSubscriptionCookieFailedToSetSubscriptionCookie
case privacyProDeadTokenDetected
case authV1MigrationFailed
case authV1MigrationSucceeded

// MARK: Pixel Experiment
case pixelExperimentEnrollment
Expand Down Expand Up @@ -1756,6 +1758,8 @@ extension Pixel.Event {
case .privacyProSubscriptionCookieRefreshedWithEmptyValue: return "m_privacy-pro_subscription-cookie-refreshed_with_empty_value"
case .privacyProSubscriptionCookieFailedToSetSubscriptionCookie: return "m_privacy-pro_subscription-cookie-failed_to_set_subscription_cookie"
case .privacyProDeadTokenDetected: return "m_privacy-pro_dead_token_detected"
case .authV1MigrationFailed: return "m_privacy-pro_v1migration_failed"
case .authV1MigrationSucceeded: return "m_privacy-pro_v1migration_succeeded"

// MARK: Pixel Experiment
case .pixelExperimentEnrollment: return "pixel_experiment_enrollment"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"location" : "https://github.com/DuckDuckGo/BrowserServicesKit",
"state" : {
"branch" : "fcappelli/subscription_oauth_api_v2",
"revision" : "e6591e5fc40cc32e6309fa4ff4f1e2dfbb865833"
"revision" : "9fd4aeaef05e212b8e93cd5e025c0ae38f013453"
}
},
{
Expand Down
6 changes: 6 additions & 0 deletions DuckDuckGo/AppDependencyProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ final class AppDependencyProvider: DependencyProvider {
switch type {
case .deadToken:
Pixel.fire(pixel: .privacyProDeadTokenDetected)
case .subscriptionIsActive:
DailyPixel.fire(pixel: .privacyProSubscriptionActive)
case .v1MigrationFailed:
Pixel.fire(pixel: .authV1MigrationFailed)
case .v1MigrationSuccessful:
Pixel.fire(pixel: .authV1MigrationSucceeded)
}
}
let subscriptionManager = DefaultSubscriptionManager(storePurchaseManager: storePurchaseManager,
Expand Down
10 changes: 5 additions & 5 deletions DuckDuckGo/AppLifecycle/AppStates/Active.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ struct Active: AppState {
}
}

AppDependencyProvider.shared.subscriptionManager.refreshCachedSubscription { isSubscriptionActive in
if isSubscriptionActive {
DailyPixel.fire(pixel: .privacyProSubscriptionActive)
}
}
// AppDependencyProvider.shared.subscriptionManager.refreshCachedSubscription { isSubscriptionActive in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this commented out?

// if isSubscriptionActive {
// DailyPixel.fire(pixel: .privacyProSubscriptionActive)
// }
// }

Task {
await appDependencies.subscriptionService.subscriptionCookieManager.refreshSubscriptionCookie()
Expand Down
6 changes: 4 additions & 2 deletions DuckDuckGo/AppLifecycle/AppStates/Launched.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ struct Launched: AppState {
@UserDefaultsWrapper(key: .privacyConfigCustomURL, defaultValue: nil)
var privacyConfigCustomURL: String?

Task {
await AppDependencyProvider.shared.subscriptionManager.loadInitialData()
}

application = stateContext.application
privacyProDataReporter = PrivacyProDataReporter(fireproofing: fireproofing)
vpnWorkaround = VPNRedditSessionWorkaround(subscriptionManager: AppDependencyProvider.shared.subscriptionManager,
Expand Down Expand Up @@ -460,8 +464,6 @@ struct Launched: AppState {

widgetRefreshModel.beginObservingVPNStatus()

AppDependencyProvider.shared.subscriptionManager.loadInitialData()

let autofillUsageMonitor = AutofillUsageMonitor()
autofillPixelReporter = AutofillPixelReporter(
userDefaults: .standard,
Expand Down
16 changes: 9 additions & 7 deletions DuckDuckGo/OldAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ final class OldAppDelegate: NSObject, UIApplicationDelegate, DDGApp {

self.voiceSearchHelper.migrateSettingsFlagIfNecessary()

Task {
await AppDependencyProvider.shared.subscriptionManager.loadInitialData()
}

// Task handler registration needs to happen before the end of `didFinishLaunching`, otherwise submitting a task can throw an exception.
// Having both in `didBecomeActive` can sometimes cause the exception when running on a physical device, so registration happens here.
AppConfigurationFetch.registerBackgroundRefreshTaskHandler()
Expand All @@ -475,8 +479,6 @@ final class OldAppDelegate: NSObject, UIApplicationDelegate, DDGApp {

widgetRefreshModel.beginObservingVPNStatus()

AppDependencyProvider.shared.subscriptionManager.loadInitialData()

setUpAutofillPixelReporter()

if didCrashDuringCrashHandlersSetUp {
Expand Down Expand Up @@ -717,11 +719,11 @@ final class OldAppDelegate: NSObject, UIApplicationDelegate, DDGApp {
}
}

AppDependencyProvider.shared.subscriptionManager.refreshCachedSubscription { isSubscriptionActive in
if isSubscriptionActive {
DailyPixel.fire(pixel: .privacyProSubscriptionActive)
}
}
// AppDependencyProvider.shared.subscriptionManager.refreshCachedSubscription { isSubscriptionActive in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this commented out?

// if isSubscriptionActive {
// DailyPixel.fire(pixel: .privacyProSubscriptionActive)
// }
// }

Task {
await subscriptionCookieManager.refreshSubscriptionCookie()
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/SettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ extension SettingsViewModel {
state.subscription.subscriptionExist = true
state.subscription.platform = subscription.platform
state.subscription.hasActiveSubscription = subscription.isActive
let features = await subscriptionManager.currentSubscriptionFeatures(forceRefresh: true)
let features = await subscriptionManager.currentSubscriptionFeatures(forceRefresh: false)
state.subscription.entitlements = features.compactMap({ feature in
if feature.enabled {
return feature.entitlement
Expand Down
37 changes: 19 additions & 18 deletions DuckDuckGo/Subscription/Feedback/UnifiedFeedbackFormViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,25 +158,26 @@ final class UnifiedFeedbackFormViewModel: ObservableObject {
self.defaultMetadataCollector = defaultMetadatCollector
self.feedbackSender = feedbackSender
self.source = source.rawValue
}

Task {
let features = await subscriptionManager.currentSubscriptionFeatures(forceRefresh: false)
let vpnFeature = features.first { $0.entitlement == .networkProtection }
let dbpFeature = features.first { $0.entitlement == .dataBrokerProtection }
let itrFeature = features.first { $0.entitlement == .identityTheftRestoration }
let itrgFeature = features.first { $0.entitlement == .identityTheftRestorationGlobal }

if vpnFeature?.enabled ?? false {
availableCategories.append(.vpn)
}
if dbpFeature?.enabled ?? false {
availableCategories.append(.pir)
}
let idpEnabled = itrFeature?.enabled ?? false
let idpgEnabled = itrgFeature?.enabled ?? false
if idpEnabled || idpgEnabled {
availableCategories.append(.itr)
}
@MainActor
func updateCategories() async {
let features = await subscriptionManager.currentSubscriptionFeatures(forceRefresh: false)
let vpnFeature = features.first { $0.entitlement == .networkProtection }
let dbpFeature = features.first { $0.entitlement == .dataBrokerProtection }
let itrFeature = features.first { $0.entitlement == .identityTheftRestoration }
let itrgFeature = features.first { $0.entitlement == .identityTheftRestorationGlobal }

if vpnFeature?.enabled ?? false {
availableCategories.append(.vpn)
}
if dbpFeature?.enabled ?? false {
availableCategories.append(.pir)
}
let idpEnabled = itrFeature?.enabled ?? false
let idpgEnabled = itrgFeature?.enabled ?? false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong names "idp" should be "itr" instead

if idpEnabled || idpgEnabled {
availableCategories.append(.itr)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct UnifiedFeedbackRootView: View {
}
.onFirstAppear {
Task {
await viewModel.updateCategories()
await viewModel.process(action: .reportActions)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,17 @@ final class SubscriptionSettingsViewModel: ObservableObject {
setupNotificationObservers()
}

private var dateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateStyle = .long
formatter.timeStyle = .none
return formatter
private var dateFormatter = {
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .long
#if DEBUG
dateFormatter.timeStyle = .medium
#else
dateFormatter.timeStyle = .none
#endif
return dateFormatter
}()

func onFirstAppear() {
Task {
// Load initial state from the cache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,8 @@ final class NetworkProtectionPacketTunnelProvider: PacketTunnelProvider {
switch type {
case .deadToken:
Pixel.fire(pixel: .privacyProDeadTokenDetected)
case .subscriptionIsActive, .v1MigrationFailed, .v1MigrationSuccessful: // handled by the main app only
break
}
}
let subscriptionManager = DefaultSubscriptionManager(storePurchaseManager: storePurchaseManager,
Expand Down Expand Up @@ -526,7 +528,7 @@ final class NetworkProtectionPacketTunnelProvider: PacketTunnelProvider {
snoozeTimingStore: NetworkProtectionSnoozeTimingStore(userDefaults: .networkProtectionGroupDefaults),
wireGuardInterface: DefaultWireGuardInterface(),
keychainType: .dataProtection(.unspecified),
tokenProvider: subscriptionManager,
subscriptionManager: subscriptionManager,
debugEvents: Self.networkProtectionDebugEvents(controllerErrorStore: errorStore),
providerEvents: Self.packetTunnelProviderEvents,
settings: settings,
Expand Down