firebase / firebase-ios-sdk

Firebase SDK for Apple App Development
https://firebase.google.com
Apache License 2.0
5.55k stars 1.45k forks source link

Phone Auth not working above iOS 16 #13479

Closed KunalxBhandari closed 2 weeks ago

KunalxBhandari commented 1 month ago

Description

I'm using the latest firebase version 11.0.0 and on iOS 16 and above, I'm unable to login using PhoneAuthProvider. I'm getting the below error message:

Error Domain=FIRAuthErrorDomain Code=17048 "Token mismatch" UserInfo={FIRAuthErrorUserInfoNameKey=INVALID_APP_CREDENTIAL, NSLocalizedDescription=Token mismatch}

Although it's working fine on 10.29.0 version.

Reproducing the issue

PhoneAuthProvider.provider().verifyPhoneNumber("+911234567899", uiDelegate: nil) { [weak self] (verificationID , error) in if let error = error { print(error) let authErr = error as NSError let alert = UIAlertController(title: "Something went wrong. Please try again later", message: nil, preferredStyle: .alert) alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil)) self?.present(alert, animated: true, completion: nil) } else { //Successful } }

Firebase SDK Version

11.0.0

Xcode Version

15.4

Installation Method

CocoaPods

Firebase Product(s)

Authentication

Targeted Platforms

iOS

Relevant Log Output

Error Domain=FIRAuthErrorDomain Code=17048 "Token mismatch" UserInfo={FIRAuthErrorUserInfoNameKey=INVALID_APP_CREDENTIAL, NSLocalizedDescription=Token mismatch}

If using Swift Package Manager, the project's Package.resolved

Expand Package.resolved snippet
```json Replace this line with the contents of your Package.resolved. ```

If using CocoaPods, the project's Podfile.lock

Expand Podfile.lock snippet
```yml Replace this line with the contents of your Podfile.lock! ```
google-oss-bot commented 1 month ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

ncooke3 commented 1 month ago

Hi @KunalxBhandari, I wasn't able to reproduce this in v11. I tried Xcode 15 and Xcode 16 and used a device running iOS 17. When PhoneAuthProvider.provider().verifyPhoneNumber(...) is called, what behavior do you see? Does anything happen (e.g. recaptcha window appear, etc.) before the callback is called with the error?

cc: @jordanebelanger

ncooke3 commented 1 month ago

If the issue can be easily reproduced, it would be helpful to know where the error is being thrown as there are a few places within the phone provider logic where it could occur.

To debug, enable Swift error breakpoints, run the app, and perform the behavior that makes the error appear. Execution may pause on a few false positives, but what we are looking for are any breakpoints that pause execution in the PhoneAuthProvider.swift file.

Screenshot 2024-08-12 at 5 59 16 PM

Knowing where those pauses occur would help narrow things down.

alexandersandberg commented 1 month ago

Possibly related:

Since Aug 8th, we've started seeing occasional INVALID_APP_CREDENTIAL errors for the google.cloud.identitytoolkit.v2.AuthenticationService.StartMfaSignIn method.

However, we're on Firebase iOS SDK version 10.24.0 since a while back. We have not made any recent changes on our side that could have caused this.

CleanShot 2024-08-13 at 14 15 54

deirinberg commented 1 month ago

@ncooke3 we're having the same token mismatch as well. It's reproducible for us across multiple devices on 11.0. Everything was working great for us on 10.29 and earlier

I added a Swift Breakpoint Error and see that the verifyClient func in PhoneAuthProvider is failing. I get the following error message: Error Domain=FIRAuthErrorDomain Code=17048 "Token mismatch" UserInfo={NSLocalizedDescription=Token mismatch, FIRAuthErrorUserInfoNameKey=INVALID_APP_CREDENTIAL}

Not sure if this is relevant but the breakpoint was firing on the AuthBackendRPCImplementation callInternal func

ncooke3 commented 1 month ago

Thanks, @deirinberg. Question, does the Recaptcha UI flow get presented at all during the process?

brett-a commented 1 month ago

downgrading to 10.27 worked, thank you! not sure if 10.29 would work as well, I just chose 10.27.

otherwise, some relevant information:

I saw the recaptcha flow when I use the simulator, not when using the device. not sure if this is helpful, I tried to add a breakpoint, but I don't really know how to interpret the output. Here's where it went however:

Screenshot 2024-08-13 at 6 41 28 PM
deirinberg commented 1 month ago

I don't see the recaptcha UI flow on device, haven't tested on simulator

ncooke3 commented 2 weeks ago

This has been fixed by #13539 and #13519. These fixes are staged to go out in the next Firebase release, 11.2.

deirinberg commented 1 week ago

thanks @ncooke3!

ncooke3 commented 3 days ago

v11.2 released today and should resolve this issue. Thanks again for reporting!

KunalxBhandari commented 2 days ago

Thanks @ncooke3!