@@ -123,11 +123,12 @@ extension Auth: AuthInterop {
123123 return
124124 }
125125 // Call back with current user token.
126- currentUser. internalGetToken ( forceRefresh: forceRefresh) { token, error in
127- DispatchQueue . main. async {
128- callback ( token, error)
126+ currentUser
127+ . internalGetToken ( forceRefresh: forceRefresh, backend: strongSelf. backend) { token, error in
128+ DispatchQueue . main. async {
129+ callback ( token, error)
130+ }
129131 }
130- }
131132 }
132133 }
133134
@@ -294,7 +295,7 @@ extension Auth: AuthInterop {
294295 requestConfiguration: self . requestConfiguration)
295296 Task {
296297 do {
297- let response = try await AuthBackend . call ( with: request)
298+ let response = try await self . backend . call ( with: request)
298299 Auth . wrapMainAsync ( callback: completion, withParam: response. signinMethods, error: nil )
299300 } catch {
300301 Auth . wrapMainAsync ( callback: completion, withParam: nil , error: error)
@@ -397,7 +398,7 @@ extension Auth: AuthInterop {
397398 let response = try await injectRecaptcha ( request: request,
398399 action: AuthRecaptchaAction . signInWithPassword)
399400 #else
400- let response = try await AuthBackend . call ( with: request)
401+ let response = try await backend . call ( with: request)
401402 #endif
402403 return try await completeSignIn (
403404 withAccessToken: response. idToken,
@@ -711,7 +712,7 @@ extension Auth: AuthInterop {
711712 let request = SignUpNewUserRequest ( requestConfiguration: self . requestConfiguration)
712713 Task {
713714 do {
714- let response = try await AuthBackend . call ( with: request)
715+ let response = try await self . backend . call ( with: request)
715716 let user = try await self . completeSignIn (
716717 withAccessToken: response. idToken,
717718 accessTokenExpirationDate: response. approximateExpirationDate,
@@ -773,7 +774,7 @@ extension Auth: AuthInterop {
773774 requestConfiguration: self . requestConfiguration)
774775 Task {
775776 do {
776- let response = try await AuthBackend . call ( with: request)
777+ let response = try await self . backend . call ( with: request)
777778 let user = try await self . completeSignIn (
778779 withAccessToken: response. idToken,
779780 accessTokenExpirationDate: response. approximateExpirationDate,
@@ -883,7 +884,7 @@ extension Auth: AuthInterop {
883884 if let inResponse {
884885 response = inResponse
885886 } else {
886- response = try await AuthBackend . call ( with: request)
887+ response = try await self . backend . call ( with: request)
887888 }
888889 let user = try await self . completeSignIn (
889890 withAccessToken: response. idToken,
@@ -995,7 +996,7 @@ extension Auth: AuthInterop {
995996 requestConfiguration: self . requestConfiguration)
996997 Task {
997998 do {
998- let response = try await AuthBackend . call ( with: request)
999+ let response = try await self . backend . call ( with: request)
9991000
10001001 let operation = ActionCodeInfo . actionCodeOperation ( forRequestType: response. requestType)
10011002 guard let email = response. email else {
@@ -1434,7 +1435,7 @@ extension Auth: AuthInterop {
14341435 /// complete, or fails. Invoked asynchronously on the main thread in the future.
14351436 @objc open func revokeToken( withAuthorizationCode authorizationCode: String ,
14361437 completion: ( ( Error ? ) -> Void ) ? = nil ) {
1437- currentUser? . internalGetToken { idToken, error in
1438+ currentUser? . internalGetToken ( backend : backend ) { idToken, error in
14381439 if let error {
14391440 Auth . wrapMainAsync ( completion, error)
14401441 return
@@ -1615,7 +1616,9 @@ extension Auth: AuthInterop {
16151616
16161617 // MARK: Internal methods
16171618
1618- init ( app: FirebaseApp , keychainStorageProvider: AuthKeychainStorage = AuthKeychainStorageReal ( ) ) {
1619+ init ( app: FirebaseApp ,
1620+ keychainStorageProvider: AuthKeychainStorage = AuthKeychainStorageReal ( ) ,
1621+ backend: AuthBackend = AuthBackend ( rpcIssuer: AuthBackendRPCIssuer ( ) ) ) {
16191622 Auth . setKeychainServiceNameForApp ( app)
16201623 self . app = app
16211624 mainBundleUrlTypes = Bundle . main
@@ -1640,6 +1643,7 @@ extension Auth: AuthInterop {
16401643 auth: nil ,
16411644 heartbeatLogger: app. heartbeatLogger,
16421645 appCheck: appCheck)
1646+ self . backend = backend
16431647 super. init ( )
16441648 requestConfiguration. auth = self
16451649
@@ -1913,17 +1917,18 @@ extension Auth: AuthInterop {
19131917 return
19141918 }
19151919 let uid = strongSelf. currentUser? . uid
1916- strongSelf. currentUser? . internalGetToken ( forceRefresh: true ) { token, error in
1917- if strongSelf. currentUser? . uid != uid {
1918- return
1919- }
1920- if error != nil {
1921- // Kicks off exponential back off logic to retry failed attempt. Starts with one minute
1922- // delay (60 seconds) if this is the first failed attempt.
1923- let rescheduleDelay = retry ? min ( delay * 2 , 16 * 60 ) : 60
1924- strongSelf. scheduleAutoTokenRefresh ( withDelay: rescheduleDelay, retry: true )
1920+ strongSelf. currentUser?
1921+ . internalGetToken ( forceRefresh: true , backend: strongSelf. backend) { token, error in
1922+ if strongSelf. currentUser? . uid != uid {
1923+ return
1924+ }
1925+ if error != nil {
1926+ // Kicks off exponential back off logic to retry failed attempt. Starts with one minute
1927+ // delay (60 seconds) if this is the first failed attempt.
1928+ let rescheduleDelay = retry ? min ( delay * 2 , 16 * 60 ) : 60
1929+ strongSelf. scheduleAutoTokenRefresh ( withDelay: rescheduleDelay, retry: true )
1930+ }
19251931 }
1926- }
19271932 }
19281933 }
19291934
@@ -2077,7 +2082,7 @@ extension Auth: AuthInterop {
20772082 requestConfiguration: requestConfiguration)
20782083 request. autoCreate = !isReauthentication
20792084 credential. prepare ( request)
2080- let response = try await AuthBackend . call ( with: request)
2085+ let response = try await backend . call ( with: request)
20812086 if response. needConfirmation {
20822087 let email = response. email
20832088 let credential = OAuthCredential ( withVerifyAssertionResponse: response)
@@ -2116,7 +2121,7 @@ extension Auth: AuthInterop {
21162121 phoneNumber: phoneNumber,
21172122 operation: operation,
21182123 requestConfiguration: requestConfiguration)
2119- return try await AuthBackend . call ( with: request)
2124+ return try await backend . call ( with: request)
21202125 case let . verification( verificationID, code) :
21212126 guard verificationID. count > 0 else {
21222127 throw AuthErrorUtils . missingVerificationIDError ( message: nil )
@@ -2128,7 +2133,7 @@ extension Auth: AuthInterop {
21282133 verificationCode: code,
21292134 operation: operation,
21302135 requestConfiguration: requestConfiguration)
2131- return try await AuthBackend . call ( with: request)
2136+ return try await backend . call ( with: request)
21322137 }
21332138 }
21342139 #endif
@@ -2154,7 +2159,7 @@ extension Auth: AuthInterop {
21542159 timestamp: credential. timestamp,
21552160 displayName: credential. displayName,
21562161 requestConfiguration: requestConfiguration)
2157- let response = try await AuthBackend . call ( with: request)
2162+ let response = try await backend . call ( with: request)
21582163 let user = try await completeSignIn ( withAccessToken: response. idToken,
21592164 accessTokenExpirationDate: response
21602165 . approximateExpirationDate,
@@ -2186,7 +2191,7 @@ extension Auth: AuthInterop {
21862191 let request = EmailLinkSignInRequest ( email: email,
21872192 oobCode: actionCode,
21882193 requestConfiguration: requestConfiguration)
2189- let response = try await AuthBackend . call ( with: request)
2194+ let response = try await backend . call ( with: request)
21902195 let user = try await completeSignIn ( withAccessToken: response. idToken,
21912196 accessTokenExpirationDate: response
21922197 . approximateExpirationDate,
@@ -2244,7 +2249,7 @@ extension Auth: AuthInterop {
22442249 private func wrapAsyncRPCTask( _ request: any AuthRPCRequest , _ callback: ( ( Error ? ) -> Void ) ? ) {
22452250 Task {
22462251 do {
2247- let _ = try await AuthBackend . call ( with: request)
2252+ let _ = try await self . backend . call ( with: request)
22482253 Auth . wrapMainAsync ( callback, nil )
22492254 } catch {
22502255 Auth . wrapMainAsync ( callback, error)
@@ -2296,7 +2301,7 @@ extension Auth: AuthInterop {
22962301 action: action)
22972302 } else {
22982303 do {
2299- return try await AuthBackend . call ( with: request)
2304+ return try await backend . call ( with: request)
23002305 } catch {
23012306 let nsError = error as NSError
23022307 if let underlyingError = nsError. userInfo [ NSUnderlyingErrorKey] as? NSError ,
@@ -2315,7 +2320,7 @@ extension Auth: AuthInterop {
23152320 }
23162321 }
23172322 }
2318- return try await AuthBackend . call ( with: request)
2323+ return try await backend . call ( with: request)
23192324 }
23202325 #endif
23212326
@@ -2332,6 +2337,8 @@ extension Auth: AuthInterop {
23322337 /// Auth's backend.
23332338 var requestConfiguration : AuthRequestConfiguration
23342339
2340+ var backend : AuthBackend
2341+
23352342 #if os(iOS)
23362343
23372344 /// The manager for APNs tokens used by phone number auth.
0 commit comments