Skip to content

Commit

Permalink
Add iOS only check
Browse files Browse the repository at this point in the history
  • Loading branch information
quanganhdo committed Mar 8, 2024
1 parent 135e922 commit ba2727c
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

import Foundation
import Common

#if os(iOS)
import Subscription
#endif

public protocol NetworkProtectionTokenStore {
/// Fetch the access token from the subscription library and convert it into a NetP auth token
Expand Down Expand Up @@ -47,12 +50,16 @@ public final class NetworkProtectionKeychainTokenStore: NetworkProtectionTokenSt
private let keychainStore: NetworkProtectionKeychainStore
private let errorEvents: EventMapping<NetworkProtectionError>?
private let isSubscriptionEnabled: Bool
#if os(iOS)
private let accountManager: AccountManaging
#endif

public func fetchSubscriptionToken() throws -> String? {
#if os(iOS)
if isSubscriptionEnabled, let accessToken = accountManager.accessToken {
return makeToken(from: accessToken)
}
#endif

return try fetchToken()
}
Expand Down Expand Up @@ -81,7 +88,9 @@ public final class NetworkProtectionKeychainTokenStore: NetworkProtectionTokenSt
keychainType: keychainType)
self.errorEvents = errorEvents
self.isSubscriptionEnabled = isSubscriptionEnabled
#if os(iOS)
self.accountManager = AccountManager(subscriptionAppGroup: subscriptionAppGroup)
#endif
}

public func store(_ token: String) throws {
Expand Down

0 comments on commit ba2727c

Please sign in to comment.