From d081efcfaca1f46b0d17d9bbb846a41a8c7a8b3d Mon Sep 17 00:00:00 2001 From: Oussama Sarhraoui Date: Thu, 1 Aug 2019 14:55:45 +0200 Subject: [PATCH 1/2] Fix: TouchID prompt on second install while it supposed to ask for permission again --- Source/UI/Coordinators/PasswordCoordinator.swift | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Source/UI/Coordinators/PasswordCoordinator.swift b/Source/UI/Coordinators/PasswordCoordinator.swift index 671852d5..0cde83ac 100644 --- a/Source/UI/Coordinators/PasswordCoordinator.swift +++ b/Source/UI/Coordinators/PasswordCoordinator.swift @@ -8,6 +8,7 @@ import UIKit private struct Constants { static let BiometricsSecretsLabel = "com.schibsted.account.biometrics.secrets" + static let HasLoggedInBeforeSettingsKey = "hasLoggedInBefore" } class PasswordCoordinator: AuthenticationCoordinator, RouteHandler { @@ -241,6 +242,11 @@ extension PasswordCoordinator { // Fallback to passsword login return nil } + + let hasLoggedInBefore = Settings.value(forKey: Constants.HasLoggedInBeforeSettingsKey) as? Bool + if hasLoggedInBefore == nil { + return nil + } var query = [String: Any]() query[kSecClass as String] = kSecClassGenericPassword query[kSecReturnData as String] = kCFBooleanTrue @@ -308,14 +314,14 @@ extension PasswordCoordinator { dictionary[kSecValueData as String] = password.data(using: .utf8)! as CFData dictionary[kSecAttrAccessControl as String] = accessControl - let hasLoggedInBeforeSettingsKey = "hasLoggedInBefore" - if let hasLoggedInBefore = Settings.value(forKey: hasLoggedInBeforeSettingsKey) as? Bool, hasLoggedInBefore { + + if let hasLoggedInBefore = Settings.value(forKey: Constants.HasLoggedInBeforeSettingsKey) as? Bool, hasLoggedInBefore { if self.configuration.useBiometrics { SecItemAdd(dictionary as CFDictionary, nil) } completion() } else { - Settings.setValue(true, forKey: hasLoggedInBeforeSettingsKey) + Settings.setValue(true, forKey: Constants.HasLoggedInBeforeSettingsKey) if self.biometryType == .touchID { let viewModel = PasswordViewModel( identifier: identifier, From fb7b038ddb2ef0a60fdf229cbbf4f28b18b7f247 Mon Sep 17 00:00:00 2001 From: Oussama Sarhraoui Date: Thu, 1 Aug 2019 16:49:19 +0200 Subject: [PATCH 2/2] Fix reviw comments --- Source/UI/Coordinators/PasswordCoordinator.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/UI/Coordinators/PasswordCoordinator.swift b/Source/UI/Coordinators/PasswordCoordinator.swift index 0cde83ac..745f9dbc 100644 --- a/Source/UI/Coordinators/PasswordCoordinator.swift +++ b/Source/UI/Coordinators/PasswordCoordinator.swift @@ -8,7 +8,10 @@ import UIKit private struct Constants { static let BiometricsSecretsLabel = "com.schibsted.account.biometrics.secrets" - static let HasLoggedInBeforeSettingsKey = "hasLoggedInBefore" + static let HasLoggedInBeforeSettingsKey = "com.schibsted.account.hasLoggedInBefore" + + // Avoid the creation of an instance of Constants + private init() {} } class PasswordCoordinator: AuthenticationCoordinator, RouteHandler { @@ -238,15 +241,11 @@ extension PasswordCoordinator { self.navigationController.pushViewController(viewController, animated: true) } private func getPasswordFromKeychain(for identifier: Identifier, _ localizedReasonString: String) -> String? { - guard #available(iOS 11.3, *) else { + guard #available(iOS 11.3, *), let hasLoggedInBefore = Settings.value(forKey: Constants.HasLoggedInBeforeSettingsKey) as? Bool else { // Fallback to passsword login return nil } - let hasLoggedInBefore = Settings.value(forKey: Constants.HasLoggedInBeforeSettingsKey) as? Bool - if hasLoggedInBefore == nil { - return nil - } var query = [String: Any]() query[kSecClass as String] = kSecClassGenericPassword query[kSecReturnData as String] = kCFBooleanTrue @@ -259,6 +258,7 @@ extension PasswordCoordinator { if status == noErr, let qresult = queryResult as? Data, let password = String(data: qresult as Data, encoding: .utf8) { return password } else { + Settings.setValue(false, forKey: Constants.HasLoggedInBeforeSettingsKey) return nil } }