Persistent internal-error from getIdToken(true) on iOS App Resume for Apple Sign-In Users, Even After Successful reauthenticateWithCredential #17457
Unanswered
eternistarr
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We are experiencing a persistent issue on iOS with Firebase Authentication for users signed in via Apple. When the app resumes after being backgrounded (especially after a period that could simulate deep sleep), calling FirebaseAuth.instance.currentUser.getIdToken(true) consistently fails with a [firebase_auth/internal-error]. The full error message is typically: An internal error has occurred, print and inspect the error details for more information.
We attempted a recovery flow where, upon encountering this internal-error for an Apple Sign-In user, we:
Successfully obtained fresh Apple credentials using SignInWithApple.getAppleIDCredential().
Created a new OAuthCredential for Firebase using these Apple credentials.
Successfully called FirebaseAuth.instance.currentUser.reauthenticateWithCredential() with the new Firebase OAuthCredential. This call reports success, and logs indicate the Firebase token is updated (e.g., [FirebaseAuth][I-AUT000017] Has valid access token. Estimated expiration date: <new_future_date>).
However, despite this successful re-authentication sequence, on the very next app resume (even if it occurs within seconds), the call to FirebaseAuth.instance.currentUser.getIdToken(true) again fails with the same [firebase_auth/internal-error]. This creates a situation where the session remains unstable, leading to the user being signed out to prevent an infinite loop of re-authentication prompts if we were to retry the Apple Sign-In flow.
Here's a condensed log sequence illustrating one cycle of this problem after a successful sign-in:
flutter: [AuthWrapper] App resumed on ios.
flutter: [AuthWrapper] iOS: Delay complete. Processing resume for user <USER_UID>.
flutter: [FirebaseAuth][I-AUT000017] Fetching new token from backend.
flutter: [AuthWrapper] iOS: Error during direct ID token refresh: Code: internal-error, Message: An internal error has occurred, print and inspect the error details for more information.
flutter: [AuthWrapper] iOS: User signed in with Apple: true
flutter: [AuthWrapper] iOS: Attempting Apple re-authentication due to internal-error.
flutter: [AuthService] reauthenticateWithAppleSignIn: Starting Apple Sign-In for re-authentication.
...
flutter: [AuthService] reauthenticateWithAppleSignIn: Successfully obtained Apple credentials.
flutter: [AuthService] reauthenticateWithAppleSignIn: Attempting Firebase re-authentication for user <USER_UID>.
...
11.13.0 - [FirebaseAuth][I-AUT000017] Has valid access token. Estimated expiration date: <NEW_EXPIRY_TIME_AFTER_REAUTH>, current date: <CURRENT_TIME>
flutter: [AuthService] reauthenticateWithAppleSignIn: Firebase re-authentication successful.
flutter: AuthService: User reloaded successfully.
flutter: [AuthWrapper] iOS: Apple re-authentication successful. User session restored.
// On IMMEDIATE NEXT APP RESUME (simulated by backgrounding/foregrounding quickly)
flutter: [AuthWrapper] App resumed on ios.
flutter: [AuthWrapper] iOS: Delay complete. Processing resume for user <USER_UID>.
flutter: [FirebaseAuth][I-AUT000017] Fetching new token from backend.
flutter: [AuthWrapper] iOS: Error during direct ID token refresh: Code: internal-error, Message: An internal error has occurred, print and inspect the error details for more information.
// (At this point, our app signs the user out to prevent a loop if the re-auth was recent)
This behavior suggests that reauthenticateWithCredential for Apple Sign-In users on iOS might not be fully stabilizing the session against this particular internal-error when getIdToken(true) is subsequently called on app resume. The initial sign-in with Apple works perfectly and results in a stable session until the app is backgrounded and resumed after some time. Any insights or guidance on why a successful re-authentication doesn't prevent the immediate recurrence of this internal-error would be greatly appreciated.
Issue Occurs on simulator and physical devices.
Packages in use:
firebase_core: ^3.14.0
firebase_auth: ^5.6.0
cloud_firestore: ^5.6.9
firebase_storage: ^12.4.7
Beta Was this translation helpful? Give feedback.
All reactions