Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -2,6 +2,10 @@ import Foundation
import enum Alamofire.AFError
import KeychainAccess

#if canImport(UIKit)
import UIKit
#endif

public enum ApplicationPasswordUseCaseError: Error {
case duplicateName
case applicationPasswordsDisabled
Expand Down Expand Up @@ -29,25 +33,6 @@ public protocol ApplicationPasswordUseCase {
func deletePassword() async throws
}

/// A wrapper for the `UIDevice` `model` and `identifierForVendor` properties.
///
/// This is necessary because `UIDevice` is part of UIKit which we cannot use when targeting watchOS.
/// So, to keep this package compatible with watchOS, we need to abstract UIKit away and delegate it to the consumers to provide us
/// with the device information.
///
/// This approach is feasible because only the `applicationPasswordName` method in
/// `DefaultApplicationPasswordUseCase` needs access to the information and watchOS does not need to create application
/// passwords. We can therefore pass a `nil` value to it to satisfy the compilation without issues for the user experience.
public struct DeviceModelIdentifierInfo {
let model: String
let identifierForVendor: String

public init(model: String, identifierForVendor: String) {
self.model = model
self.identifierForVendor = identifierForVendor
}
}

final public class DefaultApplicationPasswordUseCase: ApplicationPasswordUseCase {
/// Site Address
///
Expand All @@ -65,31 +50,27 @@ final public class DefaultApplicationPasswordUseCase: ApplicationPasswordUseCase
///
private let storage: ApplicationPasswordStorage

private let deviceModelIdentifierInfo: DeviceModelIdentifierInfo?

/// Used to name the password in wpadmin.
///
private var applicationPasswordName: String {
get {
guard let deviceModelIdentifierInfo else {
return "" // This is not needed on watchOS as the watch does not create application passwords.
}

let bundleIdentifier = Bundle.main.bundleIdentifier ?? "Unknown"
return "\(bundleIdentifier).ios-app-client.\(deviceModelIdentifierInfo.model).\(deviceModelIdentifierInfo.identifierForVendor)"
}
#if !os(watchOS)
let bundleIdentifier = Bundle.main.bundleIdentifier ?? "Unknown"
let model = UIDevice.current.model
let identifierForVendor = UIDevice.current.identifierForVendor?.uuidString ?? ""
return "\(bundleIdentifier).ios-app-client.\(model).\(identifierForVendor)"
#else
fatalError("Unexpected error: Application password should not be generated through watch app")
#endif
}

public init(username: String,
password: String,
siteAddress: String,
deviceModelIdentifierInfo: DeviceModelIdentifierInfo? = nil,
network: Network? = nil,
keychain: Keychain = Keychain(service: WooConstants.keychainServiceName)) throws {
self.siteAddress = siteAddress
self.username = username
self.storage = ApplicationPasswordStorage(keychain: keychain)
self.deviceModelIdentifierInfo = deviceModelIdentifierInfo

if let network {
self.network = network
Expand Down Expand Up @@ -154,7 +135,7 @@ final public class DefaultApplicationPasswordUseCase: ApplicationPasswordUseCase
if let uuidFromLocalPassword {
return uuidFromLocalPassword
} else {
return try await self.fetchUUIDForApplicationPassword(await applicationPasswordName)
return try await self.fetchUUIDForApplicationPassword(applicationPasswordName)
}
}()
try await deleteApplicationPassword(uuidToBeDeleted)
Expand All @@ -167,7 +148,7 @@ private extension DefaultApplicationPasswordUseCase {
/// - Returns: Generated `ApplicationPassword`
///
func createApplicationPassword() async throws -> ApplicationPassword {
let passwordName = await applicationPasswordName
let passwordName = applicationPasswordName

let parameters = [ParameterKey.name: passwordName]
let request = RESTRequest(siteURL: siteAddress, method: .post, path: Path.applicationPasswords, parameters: parameters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -752,8 +752,7 @@ private extension AuthenticationManager {
guard let useCase = try? DefaultApplicationPasswordUseCase(
username: siteCredentials.username,
password: siteCredentials.password,
siteAddress: siteCredentials.siteURL,
deviceModelIdentifierInfo: UIDevice.current.deviceModelIdentifierInfo
siteAddress: siteCredentials.siteURL
) else {
return assertionFailure("⛔️ Error creating application password use case")
}
Expand Down
1 change: 0 additions & 1 deletion WooCommerce/Classes/System/SessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ final class SessionManager: SessionManagerProtocol {
return try? DefaultApplicationPasswordUseCase(username: username,
password: password,
siteAddress: siteAddress,
deviceModelIdentifierInfo: UIDevice.current.deviceModelIdentifierInfo,
keychain: keychain)
case let .applicationPassword(_, _, siteAddress):
return OneTimeApplicationPasswordUseCase(siteAddress: siteAddress, keychain: keychain)
Expand Down

This file was deleted.

4 changes: 0 additions & 4 deletions WooCommerce/WooCommerce.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,6 @@
3F58701F281B947E004F7556 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3F58701E281B947E004F7556 /* Main.storyboard */; };
3F587021281B9494004F7556 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3F587020281B9494004F7556 /* LaunchScreen.storyboard */; };
3F587026281B9C19004F7556 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 3F587028281B9C19004F7556 /* InfoPlist.strings */; };
3F88EC3F2DF8D4BC0023A6F4 /* UIDevice+DeviceModelIdentifierInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F88EC3E2DF8D4BC0023A6F4 /* UIDevice+DeviceModelIdentifierInfo.swift */; };
4506BD712461965300FE6377 /* ProductVisibilityViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4506BD6F2461965300FE6377 /* ProductVisibilityViewController.swift */; };
4506BD722461965300FE6377 /* ProductVisibilityViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4506BD702461965300FE6377 /* ProductVisibilityViewController.xib */; };
4508BF622660E34A00707869 /* ShippingLabelCarrierAndRatesTopBanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4508BF612660E34A00707869 /* ShippingLabelCarrierAndRatesTopBanner.swift */; };
Expand Down Expand Up @@ -4480,7 +4479,6 @@
3F587037281B9C50004F7556 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/InfoPlist.strings; sourceTree = "<group>"; };
3F587038281B9C52004F7556 /* sv */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sv; path = sv.lproj/InfoPlist.strings; sourceTree = "<group>"; };
3F64F76C2C06A3A50085DEEF /* WooCommerce.release-alpha.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "WooCommerce.release-alpha.xcconfig"; sourceTree = "<group>"; };
3F88EC3E2DF8D4BC0023A6F4 /* UIDevice+DeviceModelIdentifierInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIDevice+DeviceModelIdentifierInfo.swift"; sourceTree = "<group>"; };
3FF314EF26FC784A0012E68E /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Platforms/iPhoneOS.platform/Developer/Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };
4506BD6F2461965300FE6377 /* ProductVisibilityViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductVisibilityViewController.swift; sourceTree = "<group>"; };
4506BD702461965300FE6377 /* ProductVisibilityViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ProductVisibilityViewController.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -11066,7 +11064,6 @@
DE6906E627D74A1900735E3B /* WooSplitViewController.swift */,
26A7C8782BE91F3D00382627 /* WatchDependenciesSynchronizer.swift */,
26B249702BEC801400730730 /* WatchDependencies.swift */,
3F88EC3E2DF8D4BC0023A6F4 /* UIDevice+DeviceModelIdentifierInfo.swift */,
);
path = System;
sourceTree = "<group>";
Expand Down Expand Up @@ -16257,7 +16254,6 @@
205B7ECD2C19FD2F00D14A36 /* PointOfSaleCardPresentPaymentDisplayReaderMessageMessageViewModel.swift in Sources */,
2DB877522E25466C0001B175 /* ShippingItemRowAccessibility.swift in Sources */,
DEF8CF1F29AC870A00800A60 /* WPComEmailLoginViewModel.swift in Sources */,
3F88EC3F2DF8D4BC0023A6F4 /* UIDevice+DeviceModelIdentifierInfo.swift in Sources */,
74A33D8021C3F234009E25DE /* LicensesViewController.swift in Sources */,
454453CA27566CDE00464AC5 /* HubMenuViewModel.swift in Sources */,
934CB123224EAB150005CCB9 /* main.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion config/Version.Public.xcconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CURRENT_PROJECT_VERSION = $VERSION_LONG
MARKETING_VERSION = $VERSION_SHORT
VERSION_LONG = 23.0.0.0
VERSION_SHORT = 23.0
VERSION_SHORT = 23.0