Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle subscription-related iOS use cases #728

Merged
merged 25 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2aeb4d8
Deprecate NetP token storage
quanganhdo Mar 8, 2024
135e922
Deprecate token exchange call
quanganhdo Mar 8, 2024
ba2727c
Add iOS only check
quanganhdo Mar 8, 2024
86e39cf
Fix Swiftlint
quanganhdo Mar 8, 2024
f761a63
Fix tests
quanganhdo Mar 8, 2024
cab7b56
Fix Swiftlint
quanganhdo Mar 8, 2024
9a916c3
Refactor
quanganhdo Mar 8, 2024
073eff2
Merge branch 'main' into anh/netp-subscription-clean-up
quanganhdo Mar 11, 2024
ff9de62
Also shut down VPN when encountering 403 error
quanganhdo Mar 11, 2024
823e085
Pass cachePolicy from hasEntitlements to fetchEntitlements
quanganhdo Mar 11, 2024
a014597
Merge branch 'main' into anh/netp-subscription-clean-up
quanganhdo Mar 11, 2024
3191720
Merge branch 'main' into anh/netp-pre-launch
quanganhdo Mar 12, 2024
4e2c240
Update endpoint selection code
quanganhdo Mar 12, 2024
f5ba50d
Words
quanganhdo Mar 14, 2024
d9cc0b7
Merge branch 'main' into anh/netp-pre-launch
quanganhdo Mar 14, 2024
b29a1c2
Update token store
quanganhdo Mar 15, 2024
0f01af6
Refactor
quanganhdo Mar 15, 2024
66f5613
Merge branch 'main' into anh/netp-pre-launch
quanganhdo Mar 15, 2024
730bd82
Add reset command
quanganhdo Mar 15, 2024
6e0f3cf
Add comments
quanganhdo Mar 18, 2024
7dc4670
Add subscriptionOverrideEnabled
quanganhdo Mar 18, 2024
439751b
Merge branch 'main' into anh/netp-pre-launch
quanganhdo Mar 18, 2024
a48989a
Stop using waitlist auth token when subscription is enabled
quanganhdo Mar 18, 2024
c7f1f20
Update endpoint
quanganhdo Mar 18, 2024
0322224
Merge branch 'main' into anh/netp-pre-launch
quanganhdo Mar 18, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ public final class NetworkProtectionKeychainTokenStore: NetworkProtectionTokenSt
private let isSubscriptionEnabled: Bool
private let accessTokenProvider: () -> String?

private static var authTokenPrefix: String { "ddg:" }
public static var authTokenPrefix: String { "ddg:" }

public struct Defaults {
static let tokenStoreEntryLabel = "DuckDuckGo Network Protection Auth Token"
public static let tokenStoreService = "com.duckduckgo.networkprotection.authToken"
static let tokenStoreName = "com.duckduckgo.networkprotection.token"
}

/// - isSubscriptionEnabled: Controls whether the subscription access token is used to authenticate with the NetP backend
/// - accessTokenProvider: Defines how to actually retrieve the subscription access token
public init(keychainType: KeychainType,
serviceName: String = Defaults.tokenStoreService,
errorEvents: EventMapping<NetworkProtectionError>?,
Expand All @@ -74,13 +76,13 @@ public final class NetworkProtectionKeychainTokenStore: NetworkProtectionTokenSt
}
}

public func makeToken(from subscriptionAccessToken: String) -> String {
private func makeToken(from subscriptionAccessToken: String) -> String {
Self.authTokenPrefix + subscriptionAccessToken
}

public func fetchToken() throws -> String? {
if isSubscriptionEnabled, let authToken = accessTokenProvider() {
return makeToken(from: authToken)
if isSubscriptionEnabled {
return accessTokenProvider().map { makeToken(from: $0) }
}

do {
Expand Down Expand Up @@ -114,6 +116,3 @@ public final class NetworkProtectionKeychainTokenStore: NetworkProtectionTokenSt
errorEvents?.fire(error.networkProtectionError)
}
}

extension NetworkProtectionTokenStore {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// UserDefaults+showEntitlementMessaging.swift
// UserDefaults+showMessaging.swift
//
// Copyright © 2024 DuckDuckGo. All rights reserved.
//
Expand Down Expand Up @@ -85,3 +85,24 @@ extension UserDefaults {
public extension Notification.Name {
static let vpnEntitlementMessagingDidChange = Notification.Name("com.duckduckgo.network-protection.entitlement-messaging-changed")
}

extension UserDefaults {
private var vpnEarlyAccessOverAlertAlreadyShownKey: String {
"vpnEarlyAccessOverAlertAlreadyShown"
}

@objc
public dynamic var vpnEarlyAccessOverAlertAlreadyShown: Bool {
get {
value(forKey: vpnEarlyAccessOverAlertAlreadyShownKey) as? Bool ?? false
}

set {
set(newValue, forKey: vpnEarlyAccessOverAlertAlreadyShownKey)
}
}

public func resetThankYouMessaging() {
removeObject(forKey: vpnEarlyAccessOverAlertAlreadyShownKey)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// UserDefaults+subscriptionOverrideEnabled.swift
//
// Copyright © 2024 DuckDuckGo. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Combine
import Foundation

extension UserDefaults {
private var subscriptionOverrideEnabledKey: String {
"subscriptionOverrideEnabled"
}

public var subscriptionOverrideEnabled: Bool? {
get {
value(forKey: subscriptionOverrideEnabledKey) as? Bool
}

set {
set(newValue, forKey: subscriptionOverrideEnabledKey)
}
}

public func resetsubscriptionOverrideEnabled() {
removeObject(forKey: subscriptionOverrideEnabledKey)
}
}
Loading