@@ -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
@@ -292,7 +293,7 @@ extension Auth: AuthInterop {
292293 requestConfiguration: self . requestConfiguration)
293294 Task {
294295 do {
295- let response = try await AuthBackend . call ( with: request)
296+ let response = try await self . backend . call ( with: request)
296297 Auth . wrapMainAsync ( callback: completion, withParam: response. signinMethods, error: nil )
297298 } catch {
298299 Auth . wrapMainAsync ( callback: completion, withParam: nil , error: error)
@@ -395,7 +396,7 @@ extension Auth: AuthInterop {
395396 let response = try await injectRecaptcha ( request: request,
396397 action: AuthRecaptchaAction . signInWithPassword)
397398 #else
398- let response = try await AuthBackend . call ( with: request)
399+ let response = try await backend . call ( with: request)
399400 #endif
400401 return try await completeSignIn (
401402 withAccessToken: response. idToken,
@@ -709,7 +710,7 @@ extension Auth: AuthInterop {
709710 let request = SignUpNewUserRequest ( requestConfiguration: self . requestConfiguration)
710711 Task {
711712 do {
712- let response = try await AuthBackend . call ( with: request)
713+ let response = try await self . backend . call ( with: request)
713714 let user = try await self . completeSignIn (
714715 withAccessToken: response. idToken,
715716 accessTokenExpirationDate: response. approximateExpirationDate,
@@ -771,7 +772,7 @@ extension Auth: AuthInterop {
771772 requestConfiguration: self . requestConfiguration)
772773 Task {
773774 do {
774- let response = try await AuthBackend . call ( with: request)
775+ let response = try await self . backend . call ( with: request)
775776 let user = try await self . completeSignIn (
776777 withAccessToken: response. idToken,
777778 accessTokenExpirationDate: response. approximateExpirationDate,
@@ -881,7 +882,7 @@ extension Auth: AuthInterop {
881882 if let inResponse {
882883 response = inResponse
883884 } else {
884- response = try await AuthBackend . call ( with: request)
885+ response = try await self . backend . call ( with: request)
885886 }
886887 let user = try await self . completeSignIn (
887888 withAccessToken: response. idToken,
@@ -993,7 +994,7 @@ extension Auth: AuthInterop {
993994 requestConfiguration: self . requestConfiguration)
994995 Task {
995996 do {
996- let response = try await AuthBackend . call ( with: request)
997+ let response = try await self . backend . call ( with: request)
997998
998999 let operation = ActionCodeInfo . actionCodeOperation ( forRequestType: response. requestType)
9991000 guard let email = response. email else {
@@ -1433,7 +1434,7 @@ extension Auth: AuthInterop {
14331434 /// complete, or fails. Invoked asynchronously on the main thread in the future.
14341435 @objc open func revokeToken( withAuthorizationCode authorizationCode: String ,
14351436 completion: ( ( Error ? ) -> Void ) ? = nil ) {
1436- currentUser? . internalGetToken { idToken, error in
1437+ currentUser? . internalGetToken ( backend : backend ) { idToken, error in
14371438 if let error {
14381439 Auth . wrapMainAsync ( completion, error)
14391440 return
@@ -1613,7 +1614,9 @@ extension Auth: AuthInterop {
16131614
16141615 // MARK: Internal methods
16151616
1616- init ( app: FirebaseApp , keychainStorageProvider: AuthKeychainStorage = AuthKeychainStorageReal ( ) ) {
1617+ init ( app: FirebaseApp ,
1618+ keychainStorageProvider: AuthKeychainStorage = AuthKeychainStorageReal ( ) ,
1619+ backend: AuthBackend = AuthBackend ( rpcIssuer: AuthBackendRPCIssuer ( ) ) ) {
16171620 Auth . setKeychainServiceNameForApp ( app)
16181621 self . app = app
16191622 mainBundleUrlTypes = Bundle . main
@@ -1638,6 +1641,7 @@ extension Auth: AuthInterop {
16381641 auth: nil ,
16391642 heartbeatLogger: app. heartbeatLogger,
16401643 appCheck: appCheck)
1644+ self . backend = backend
16411645 super. init ( )
16421646 requestConfiguration. auth = self
16431647
@@ -1911,17 +1915,18 @@ extension Auth: AuthInterop {
19111915 return
19121916 }
19131917 let uid = strongSelf. currentUser? . uid
1914- strongSelf. currentUser? . internalGetToken ( forceRefresh: true ) { token, error in
1915- if strongSelf. currentUser? . uid != uid {
1916- return
1917- }
1918- if error != nil {
1919- // Kicks off exponential back off logic to retry failed attempt. Starts with one minute
1920- // delay (60 seconds) if this is the first failed attempt.
1921- let rescheduleDelay = retry ? min ( delay * 2 , 16 * 60 ) : 60
1922- strongSelf. scheduleAutoTokenRefresh ( withDelay: rescheduleDelay, retry: true )
1918+ strongSelf. currentUser?
1919+ . internalGetToken ( forceRefresh: true , backend: strongSelf. backend) { token, error in
1920+ if strongSelf. currentUser? . uid != uid {
1921+ return
1922+ }
1923+ if error != nil {
1924+ // Kicks off exponential back off logic to retry failed attempt. Starts with one minute
1925+ // delay (60 seconds) if this is the first failed attempt.
1926+ let rescheduleDelay = retry ? min ( delay * 2 , 16 * 60 ) : 60
1927+ strongSelf. scheduleAutoTokenRefresh ( withDelay: rescheduleDelay, retry: true )
1928+ }
19231929 }
1924- }
19251930 }
19261931 }
19271932
@@ -2075,7 +2080,7 @@ extension Auth: AuthInterop {
20752080 requestConfiguration: requestConfiguration)
20762081 request. autoCreate = !isReauthentication
20772082 credential. prepare ( request)
2078- let response = try await AuthBackend . call ( with: request)
2083+ let response = try await backend . call ( with: request)
20792084 if response. needConfirmation {
20802085 let email = response. email
20812086 let credential = OAuthCredential ( withVerifyAssertionResponse: response)
@@ -2114,7 +2119,7 @@ extension Auth: AuthInterop {
21142119 phoneNumber: phoneNumber,
21152120 operation: operation,
21162121 requestConfiguration: requestConfiguration)
2117- return try await AuthBackend . call ( with: request)
2122+ return try await backend . call ( with: request)
21182123 case let . verification( verificationID, code) :
21192124 guard verificationID. count > 0 else {
21202125 throw AuthErrorUtils . missingVerificationIDError ( message: nil )
@@ -2126,7 +2131,7 @@ extension Auth: AuthInterop {
21262131 verificationCode: code,
21272132 operation: operation,
21282133 requestConfiguration: requestConfiguration)
2129- return try await AuthBackend . call ( with: request)
2134+ return try await backend . call ( with: request)
21302135 }
21312136 }
21322137 #endif
@@ -2152,7 +2157,7 @@ extension Auth: AuthInterop {
21522157 timestamp: credential. timestamp,
21532158 displayName: credential. displayName,
21542159 requestConfiguration: requestConfiguration)
2155- let response = try await AuthBackend . call ( with: request)
2160+ let response = try await backend . call ( with: request)
21562161 let user = try await completeSignIn ( withAccessToken: response. idToken,
21572162 accessTokenExpirationDate: response
21582163 . approximateExpirationDate,
@@ -2184,7 +2189,7 @@ extension Auth: AuthInterop {
21842189 let request = EmailLinkSignInRequest ( email: email,
21852190 oobCode: actionCode,
21862191 requestConfiguration: requestConfiguration)
2187- let response = try await AuthBackend . call ( with: request)
2192+ let response = try await backend . call ( with: request)
21882193 let user = try await completeSignIn ( withAccessToken: response. idToken,
21892194 accessTokenExpirationDate: response
21902195 . approximateExpirationDate,
@@ -2242,7 +2247,7 @@ extension Auth: AuthInterop {
22422247 private func wrapAsyncRPCTask( _ request: any AuthRPCRequest , _ callback: ( ( Error ? ) -> Void ) ? ) {
22432248 Task {
22442249 do {
2245- let _ = try await AuthBackend . call ( with: request)
2250+ let _ = try await self . backend . call ( with: request)
22462251 Auth . wrapMainAsync ( callback, nil )
22472252 } catch {
22482253 Auth . wrapMainAsync ( callback, error)
@@ -2294,7 +2299,7 @@ extension Auth: AuthInterop {
22942299 action: action)
22952300 } else {
22962301 do {
2297- return try await AuthBackend . call ( with: request)
2302+ return try await backend . call ( with: request)
22982303 } catch {
22992304 let nsError = error as NSError
23002305 if let underlyingError = nsError. userInfo [ NSUnderlyingErrorKey] as? NSError ,
@@ -2313,7 +2318,7 @@ extension Auth: AuthInterop {
23132318 }
23142319 }
23152320 }
2316- return try await AuthBackend . call ( with: request)
2321+ return try await backend . call ( with: request)
23172322 }
23182323 #endif
23192324
@@ -2330,6 +2335,8 @@ extension Auth: AuthInterop {
23302335 /// Auth's backend.
23312336 var requestConfiguration : AuthRequestConfiguration
23322337
2338+ let backend : AuthBackend
2339+
23332340 #if os(iOS)
23342341
23352342 /// The manager for APNs tokens used by phone number auth.
0 commit comments