Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No credential.code received although credential.instantVerification is true #176

Closed
coderpradp opened this issue Oct 10, 2019 · 11 comments
Closed
Labels
android Relates to Android platform bug Something isn't working properly legacy Related to inherited code/functionality runtime issue An issue related to app runtime

Comments

@coderpradp
Copy link

coderpradp commented Oct 10, 2019

Bug report

Current behavior:
Calling verifyPhoneNumber on android triggers instantverification however no code is sent in the credential object. I do get key verified: false though which means no verificationId and no code.

Edit: The PhoneAuth user account is being created on firebase console. So, there's no doubt that verification was succesful.

Expected behavior:

Expected behavior is to get code in the credential object when credential.instantVerification is true

Environment information

  • Cordova CLI version
    • 9.0.0 (cordova-lib@9.0.1)
  • Cordova platform version
    • android 8.1.0
  • Plugins & versions installed in project (including this plugin)
    cordova-plugin-androidx 1.0.2 "cordova-plugin-androidx"
    cordova-plugin-androidx-adapter 1.1.0 "cordova-plugin-androidx-adapter"
    cordova-plugin-device 1.1.7 "Device"
    cordova-plugin-firebase-analytics 3.0.0 "FirebaseAnalyticsPlugin"
    cordova-plugin-firebase-messaging 3.0.0 "FirebaseMessagingPlugin"
    cordova-plugin-firebasex 6.1.0 "Google Firebase Plugin"
    cordova-plugin-google-analytics 1.8.6 "Google Universal Analytics Plugin"
    cordova-plugin-inappbrowser 3.0.0 "InAppBrowser"
    cordova-plugin-keyboard 1.2.0 "Keyboard"
    cordova-plugin-safariviewcontroller 1.6.0 "SafariViewController"
    cordova-plugin-screen-orientation 3.0.1 "Screen Orientation"
    cordova-plugin-splashscreen 5.0.2 "Splashscreen"
    cordova-plugin-statusbar 2.4.2 "StatusBar"
    cordova-plugin-whitelist 1.3.3 "Whitelist"
    cordova-plugin-wkwebview-engine 1.1.4 "Cordova WKWebView Engine"
    cordova-support-android-plugin 1.0.1 "cordova-support-android-plugin"
    cordova-support-google-services 1.3.1 "cordova-support-google-services"
    es6-promise-plugin 4.2.2 "Promise"
  • Dev machine OS and version, e.g.
    • Windows 10
      • Version 1903 (OS Build 18362.388)

Runtime issue

  • Device details
    • Huawei Y9 (2018)
  • OS details
    • Android 9.0

Android build issue:

  • Node JS version
    • 10.16.2

Related code:

window.FirebasePlugin.verifyPhoneNumber(phoneNumber, 0, (credential) => {
          if(typeof credential === 'object') {
            if(credential.instantVerification) {
              console.log('instant verification')
              console.log('credential.code', credential.code)
            } else {
              console.log('not instant verification')
            }
          }
        }, (error) => {
          console.log('error', error)
        })

Console output

console output

instant verification
credential.code undefined



@coderpradp
Copy link
Author

coderpradp commented Oct 11, 2019

I think this line here is not returning correct field value or there might have been changes to PhoneAuthCredential on firebase api

There had been discussion about it on original repo about this. arnesson#861

@dpa99c
Copy link
Owner

dpa99c commented Nov 9, 2019

verifyPhoneNumber() has been reworked in v7.0.0 of this plugin which should resolve your issue.
Please retest using the example project.
You can use the newly added fakeVerificationCode option to test instant verification on Android which uses the officially sanctioned method - see the updated documentation for more details.

If you still encounter issues, please respond here and I will reopen the issue to investigate.

@dpa99c dpa99c closed this as completed Nov 9, 2019
@MattGould1
Copy link

hey @dpa99c,

When I'm using the devices phone number I received instantVerification = true, without the verificationId or code. The expected output here would be with the verificationId and Code

When I'm using a phone number of a different device, I receive instantVerification = true along with the verificationId and a null code. The expected outcome here would be only the verificationId.

I've not developed any cordova plugins before but I'm going to see if I can create an PR for this.

@dpa99c
Copy link
Owner

dpa99c commented Nov 9, 2019

@MattGould1 As you can see in the source code, instantVerification: true is only ever set in the onVerificationCompleted() callback which is the instant verification callback.
In my testing using the example project, this behaved as expected and when onVerificationCompleted() was called, the verificationId and code were resolved.
Could you try to reproduce the issue using the example project?

@MattGould1
Copy link

hey @dpa99c sorry, I didn't mention that was with https://github.com/dpa99c/cordova-plugin-firebasex-test

I get the same results within my actual project as well.

@MattGould1
Copy link

MattGould1 commented Nov 10, 2019

Here's a look at what onVerificationCompleted is receiving.

credential = {PhoneAuthCredential@8547} 
  zza = null
  zzb = null
  zzc = true
  zzd = "PHONE_NUMBER"
  zze = true
  zzf = null
  zzg = null

This is what is received when using a phone number where instant verification shouldn't be possible

credential = {PhoneAuthCredential@8575} 
 zza = "AM5PThDaZfNM63JRgqowSNAjLhHTZq8ceLYKQD8j9z1kcbcWzv9kQiFziy81ghjOmEFo1S88ml-4Rdfrw3LNjzcPoJ30I270ejNROXKs21YkbTjkxmt6oXULDw283OnLJGgCE5c3pvr1w3XKFfYZKR9DzlqVSPpRl2IzVjkceeDpR3VsFvtDkv3W2RNMPraK2wmZC1HeySoag-ixq7J4I6j1fBAFOO_feL2e5PhnGjSbsRkS8s0"
 zzb = "null"
 zzc = false
 zzd = null
 zze = true
 zzf = null
 zzg = null

@coderpradp
Copy link
Author

coderpradp commented Nov 10, 2019

I can still confirm that the credential.code and credential.verificationId are not resolved although onVerificationCompleted gets called.

As I mentioned in earlier comment, there has been some changes to firebase API such that the private fields like code and verificationId of PhoneAuthCredential are hard to retrieve. I tried playing with it but couldn't get those fields.
Here is the source code which might need modifications: https://github.com/dpa99c/cordova-plugin-firebasex/blob/master/src/android/FirebasePlugin.java#L818:L827

Mind that I tried trigerring instant verification in a real android device instead of setting up test phone number in firebase console.

@MattGould1
Copy link

quick update, if this helps I'm able to sign in with the credential using FirebaseAuth.getInstance().signInWithCredential(credential)

but the credential is still missing the verificationId and code.

@MattGould1
Copy link

hey @dpa99c,

The only way to get this functionality to work for me was by implementing the native signInWithCredential method. After that, I implemented a native function to get the users idToken and then used the idToken to verify with my server.

@kyubix
Copy link

kyubix commented Nov 24, 2019

I am also encountering the same issue, I'm using plugin version v7.0.1
The only field I get at the credential object is instantVerification with true value, while credential.code and credential.verificationId field still not found
image

@dpa99c
Copy link
Owner

dpa99c commented Nov 25, 2019

The internal reflection approach inherited from cordova-plugin-firebase is the issue here.
There is no reason to extract the credentials from the native Java credential object and return it to the JS layer.
So I will rework the implementation of verifyPhoneNumber() as part of #208 to retain the credential in the native layer on both Android & iOS, which is a more stable approach.
However, be warned this will make breaking changes to the plugin API.

@dpa99c dpa99c reopened this Nov 25, 2019
@dpa99c dpa99c added android Relates to Android platform legacy Related to inherited code/functionality runtime issue An issue related to app runtime TODO Something needs doing bug Something isn't working properly labels Nov 25, 2019
dpa99c pushed a commit that referenced this issue Dec 11, 2019
@dpa99c dpa99c closed this as completed in 901142c Feb 18, 2020
@dpa99c dpa99c removed the TODO Something needs doing label Jun 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android Relates to Android platform bug Something isn't working properly legacy Related to inherited code/functionality runtime issue An issue related to app runtime
Projects
None yet
Development

No branches or pull requests

4 participants