firebase-ios-sdk icon indicating copy to clipboard operation
firebase-ios-sdk copied to clipboard

Phone Auth not working above iOS 16

Open KunalxBhandari opened this issue 1 year ago • 8 comments

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

Replace this line with the contents of your Package.resolved.

If using CocoaPods, the project's Podfile.lock

Expand Podfile.lock snippet

Replace this line with the contents of your Podfile.lock!

KunalxBhandari avatar Aug 12 '24 08:08 KunalxBhandari

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

google-oss-bot avatar Aug 12 '24 08:08 google-oss-bot

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 avatar Aug 12 '24 21:08 ncooke3

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.

ncooke3 avatar Aug 12 '24 22:08 ncooke3

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

alexandersandberg avatar Aug 13 '24 12:08 alexandersandberg

@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

deirinberg avatar Aug 13 '24 21:08 deirinberg

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

ncooke3 avatar Aug 13 '24 22:08 ncooke3

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

brett-a avatar Aug 13 '24 23:08 brett-a

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

deirinberg avatar Aug 13 '24 23:08 deirinberg

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

ncooke3 avatar Aug 29 '24 14:08 ncooke3

thanks @ncooke3!

deirinberg avatar Sep 04 '24 14:09 deirinberg

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

ncooke3 avatar Sep 10 '24 20:09 ncooke3

Thanks @ncooke3!

KunalxBhandari avatar Sep 11 '24 06:09 KunalxBhandari