From ed4269b40ceb932f82132032722fa2f6fd91c0d1 Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Fri, 6 Sep 2024 12:05:47 -0700 Subject: [PATCH] [Auth] Better keychain error descriptions (#13600) --- .../Swift/Utilities/AuthErrorUtils.swift | 3 ++- .../SettingsViewController.swift | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/FirebaseAuth/Sources/Swift/Utilities/AuthErrorUtils.swift b/FirebaseAuth/Sources/Swift/Utilities/AuthErrorUtils.swift index e4997d07c2d..dbf2dcb9a1b 100644 --- a/FirebaseAuth/Sources/Swift/Utilities/AuthErrorUtils.swift +++ b/FirebaseAuth/Sources/Swift/Utilities/AuthErrorUtils.swift @@ -371,7 +371,8 @@ class AuthErrorUtils: NSObject { } static func keychainError(function: String, status: OSStatus) -> Error { - let reason = "\(function) (\(status))" + let message = SecCopyErrorMessageString(status, nil) as String? ?? "" + let reason = "\(function) (\(status)) \(message)" return error(code: .keychainError, userInfo: [NSLocalizedFailureReasonErrorKey: reason]) } diff --git a/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/ViewControllers/SettingsViewController.swift b/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/ViewControllers/SettingsViewController.swift index e7f3b95181e..77f6a6f7d8b 100644 --- a/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/ViewControllers/SettingsViewController.swift +++ b/FirebaseAuth/Tests/SampleSwift/AuthenticationExample/ViewControllers/SettingsViewController.swift @@ -113,14 +113,19 @@ class SettingsViewController: UIViewController, DataSourceProviderDelegate { } private func toggleAccessGroup() { - if AppManager.shared.auth().userAccessGroup == nil { - guard let bundleDictionary = Bundle.main.infoDictionary, - let group = bundleDictionary["AppIdentifierPrefix"] as? String else { - fatalError("Configure AppIdentifierPrefix in the plist") + do { + if AppManager.shared.auth().userAccessGroup == nil { + guard let bundleDictionary = Bundle.main.infoDictionary, + let group = bundleDictionary["AppIdentifierPrefix"] as? String else { + fatalError("Configure AppIdentifierPrefix in the plist") + } + try AppManager.shared.auth().useUserAccessGroup(group + + "com.google.firebase.auth.keychainGroup1") + } else { + try AppManager.shared.auth().useUserAccessGroup(nil) } - AppManager.shared.auth().userAccessGroup = group + "com.google.firebase.auth.keychainGroup1" - } else { - AppManager.shared.auth().userAccessGroup = nil + } catch { + fatalError("Failed to set userAccessGroup with error \(error)") } }