@@ -1624,7 +1624,6 @@ extension Auth: AuthInterop {
1624
1624
keychainStorageProvider: AuthKeychainStorage = AuthKeychainStorageReal ( ) ,
1625
1625
backend: AuthBackend = . init( rpcIssuer: AuthBackendRPCIssuer ( ) ) ,
1626
1626
authDispatcher: AuthDispatcher = . init( ) ) {
1627
- Auth . setKeychainServiceNameForApp ( app)
1628
1627
self . app = app
1629
1628
mainBundleUrlTypes = Bundle . main
1630
1629
. object ( forInfoDictionaryKey: " CFBundleURLTypes " ) as? [ [ String : Any ] ]
@@ -1650,27 +1649,28 @@ extension Auth: AuthInterop {
1650
1649
appCheck: appCheck)
1651
1650
self . backend = backend
1652
1651
self . authDispatcher = authDispatcher
1652
+
1653
+ let keychainServiceName = Auth . keychainServiceName ( for: app)
1654
+ keychainServices = AuthKeychainServices ( service: keychainServiceName,
1655
+ storage: keychainStorageProvider)
1656
+ storedUserManager = AuthStoredUserManager (
1657
+ serviceName: keychainServiceName,
1658
+ keychainServices: keychainServices
1659
+ )
1660
+
1653
1661
super. init ( )
1654
1662
requestConfiguration. auth = self
1655
1663
1656
- protectedDataInitialization ( keychainStorageProvider )
1664
+ protectedDataInitialization ( )
1657
1665
}
1658
1666
1659
- private func protectedDataInitialization( _ keychainStorageProvider : AuthKeychainStorage ) {
1667
+ private func protectedDataInitialization( ) {
1660
1668
// Continue with the rest of initialization in the work thread.
1661
1669
kAuthGlobalWorkQueue. async { [ weak self] in
1662
1670
// Load current user from Keychain.
1663
1671
guard let self else {
1664
1672
return
1665
1673
}
1666
- if let keychainServiceName = Auth . keychainServiceName ( forAppName: self . firebaseAppName) {
1667
- self . keychainServices = AuthKeychainServices ( service: keychainServiceName,
1668
- storage: keychainStorageProvider)
1669
- self . storedUserManager = AuthStoredUserManager (
1670
- serviceName: keychainServiceName,
1671
- keychainServices: self . keychainServices
1672
- )
1673
- }
1674
1674
1675
1675
do {
1676
1676
if let storedUserAccessGroup = self . storedUserManager. getStoredUserAccessGroup ( ) {
@@ -1729,21 +1729,21 @@ extension Auth: AuthInterop {
1729
1729
1730
1730
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
1731
1731
private func addProtectedDataDidBecomeAvailableObserver( ) {
1732
- weak var weakSelf = self
1733
1732
protectedDataDidBecomeAvailableObserver =
1734
1733
NotificationCenter . default. addObserver (
1735
1734
forName: UIApplication . protectedDataDidBecomeAvailableNotification,
1736
1735
object: nil ,
1737
1736
queue: nil
1738
- ) { notification in
1739
- let strongSelf = weakSelf
1740
- if let observer = strongSelf ? . protectedDataDidBecomeAvailableObserver {
1737
+ ) { [ weak self ] notification in
1738
+ guard let self else { return }
1739
+ if let observer = self . protectedDataDidBecomeAvailableObserver {
1741
1740
NotificationCenter . default. removeObserver (
1742
1741
observer,
1743
1742
name: UIApplication . protectedDataDidBecomeAvailableNotification,
1744
1743
object: nil
1745
1744
)
1746
1745
}
1746
+ self . protectedDataInitialization ( )
1747
1747
}
1748
1748
}
1749
1749
#endif
@@ -1817,28 +1817,34 @@ extension Auth: AuthInterop {
1817
1817
/// @synchronized([FIRAuth class]) context.
1818
1818
fileprivate static var gKeychainServiceNameForAppName : [ String : String ] = [ : ]
1819
1819
1820
- /// Sets the keychain service name global data for the particular app.
1821
- /// - Parameter app: The Firebase app to set keychain service name for.
1822
- class func setKeychainServiceNameForApp( _ app: FirebaseApp ) {
1823
- objc_sync_enter ( Auth . self)
1824
- gKeychainServiceNameForAppName [ app. name] = " firebase_auth_ \( app. options. googleAppID) "
1825
- objc_sync_exit ( Auth . self)
1826
- }
1827
-
1828
- /// Gets the keychain service name global data for the particular app by name.
1829
- /// - Parameter appName: The name of the Firebase app to get keychain service name for.
1830
- class func keychainServiceName( forAppName appName: String ) -> String ? {
1820
+ /// Gets the keychain service name global data for the particular app by
1821
+ /// name, creating an entry for one if it does not exist.
1822
+ /// - Parameter app: The Firebase app to get the keychain service name for.
1823
+ /// - Returns: The keychain service name for the given app.
1824
+ static func keychainServiceName( for app: FirebaseApp ) -> String {
1831
1825
objc_sync_enter ( Auth . self)
1832
1826
defer { objc_sync_exit ( Auth . self) }
1833
- return gKeychainServiceNameForAppName [ appName]
1827
+ let appName = app. name
1828
+ if let serviceName = gKeychainServiceNameForAppName [ appName] {
1829
+ return serviceName
1830
+ } else {
1831
+ let serviceName = " firebase_auth_ \( app. options. googleAppID) "
1832
+ gKeychainServiceNameForAppName [ appName] = serviceName
1833
+ return serviceName
1834
+ }
1834
1835
}
1835
1836
1836
1837
/// Deletes the keychain service name global data for the particular app by name.
1837
1838
/// - Parameter appName: The name of the Firebase app to delete keychain service name for.
1838
- class func deleteKeychainServiceNameForAppName( _ appName: String ) {
1839
+ /// - Returns: The deleted keychain service name, if any.
1840
+ static func deleteKeychainServiceNameForAppName( _ appName: String ) -> String ? {
1839
1841
objc_sync_enter ( Auth . self)
1842
+ defer { objc_sync_exit ( Auth . self) }
1843
+ guard let serviceName = gKeychainServiceNameForAppName [ appName] else {
1844
+ return nil
1845
+ }
1840
1846
gKeychainServiceNameForAppName. removeValue ( forKey: appName)
1841
- objc_sync_exit ( Auth . self )
1847
+ return serviceName
1842
1848
}
1843
1849
1844
1850
func signOutByForce( withUserID userID: String ) throws {
@@ -2364,15 +2370,15 @@ extension Auth: AuthInterop {
2364
2370
// MARK: Private properties
2365
2371
2366
2372
/// The stored user manager.
2367
- private var storedUserManager : AuthStoredUserManager !
2373
+ private let storedUserManager : AuthStoredUserManager
2368
2374
2369
2375
/// The Firebase app name.
2370
2376
private let firebaseAppName : String
2371
2377
2372
2378
private let authDispatcher : AuthDispatcher
2373
2379
2374
2380
/// The keychain service.
2375
- private var keychainServices : AuthKeychainServices !
2381
+ private let keychainServices : AuthKeychainServices
2376
2382
2377
2383
/// The user access (ID) token used last time for posting auth state changed notification.
2378
2384
private var lastNotifiedUserToken : String ?
0 commit comments