angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

signInWithCredential error code auth/network-request-failed

Open uzumakinaruto123 opened this issue 10 years ago • 83 comments

Version info

Angular: 2.0.0-rc4

Ionic: 2.0.0-beta.35

Firebase: 3.3.0

AngularFire: 2.0.0-beta.2

Google plus sign in using signInWithCredential(idToken) .

var provider = (<any> firebase.auth.GoogleAuthProvider).credential(null,res.idToken);

     firebase.auth().signInWithCredential(provider)
      .then((success) => {
        this.navCtrl.setRoot(TabsPage);
        console.log("Firebase success: " + JSON.stringify(success));
      })
      .catch((error) => {
        this.error = error
        console.log("Firebase failure: " + JSON.stringify(error));
      });

Google sign is sucessfull and idToken is received. But , it gives 404 (Not Found) on https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyAssertion?key=<My-Api-Key> at firebase.auth().signInWithCredential() method.

Debug output

** Errors in the JavaScript console **

POST 
https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyAssertion?key=My-key 404 (Not Found)                                      zone.js:101

Firebase failure: {"code":"auth/network-request-failed","message":"A network error (such as timeout, interrupted connection or unreachable host) has occurred."}       app.bundle.js:254

Expected behavior

Should sign in into firebase using google sign in access token.

uzumakinaruto123 avatar Sep 30 '16 18:09 uzumakinaruto123

I've been trying to fix this ionic/firebase issue on my android device for 2 days straight. Worked great in browser but not on android device. Downgrading to 3.3.0 did the trick. If only I found this faster -__- Thanks!

ghost avatar May 14 '17 07:05 ghost

Hi, I'm also using ionic. I can reproduce this 100% of the time on my phone (also tested on Firefox and Chrome desktop, but never encounter this problem). cordova-plugin-whitelist is configured and has been worked in the past. I experimented a lot, the steps to reproduce is like this:

From Android phone:

  1. Use login form with login button, with or without ngSubmit, does not matter
  2. Tap and enter email and password
  3. While device keyboard is still opened, press enter (big right arrow on some keyboards) or the login button and auth/network-request-failed will be thrown
  4. Tap somewhere else to close the keyboard, press the login button and auth/network-request-failed will be thrown again
  5. Tap into email or password input, press enter (big right arrow on some keyboards) or the login button and now it will log in successfully

It should has nothing to do with the keyboard or input focus / refocus but I don't have any clue either.

Finally I tried downgrading to 3.3.0 and it solved the issue. But this should not be an acceptable workaround.

I think we should also try the recent Firebase SDK 4.0.0 and since it is open sourced it should be easier to debug (https://github.com/firebase/firebase-js-sdk). I will try and if the problem still persist I think we should open the new issue there.

deoxen0n2 avatar May 19 '17 17:05 deoxen0n2

I have this issue with 0.5% of the user requests, which is low but that's a lot of users. (using v3.9). Has anyone tried v4.0?

brunolemos avatar May 31 '17 05:05 brunolemos

+1

iturn avatar Jun 14 '17 10:06 iturn

same problem here ... inconsistent and impossible to reproduce for now.

pvdyck avatar Jun 14 '17 10:06 pvdyck

I have this issue with angularfire-4.0.0 1_png

iturn avatar Jun 14 '17 10:06 iturn

Including the cordova-plugin-network-information corrected this issue for me. I confirmed that the 'navigator.onLine' was occasionally 'false', which I believe was causing Firebase to think there was an issue. Once I added the cordova-plugin-network-information to my project, the problem went away. I didn't dig deep into why, but I suspect this plugin has a better wrapper around the navigator which may be giving Firebase better information. I did confirm this problem came back after removing the plugin, but re-applying it fixes it. I will update this if I dig deeper. I hope this helps.

washowasho avatar Jul 05 '17 21:07 washowasho

@washowasho interesting, so in theory this should help:

 Object.defineProperty(navigator, 'onLine', {
   get: function() { return true; },
   set: function() {}
 });

brunolemos avatar Jul 05 '17 21:07 brunolemos

@washowasho THANK YOU SO MUCH!!! Solved it for me!

razgriz-detroit avatar Jul 10 '17 16:07 razgriz-detroit

Looks like this may have been solved in the latest release of Firebase 4.2.0. I'll be verifying when I get a chance.

"Refactored to not use navigator.onLine for offline detection in Cordova environments."

https://firebase.google.com/support/release-notes/js#4.2.0

washowasho avatar Aug 04 '17 01:08 washowasho

Seems like after I downgrade firebase to 3.3.0 it is resolved. Before this I was continuously getting 'auth/network-request-failed'. Let me know if there is solution for this in newer versions.

ghost avatar Aug 16 '17 17:08 ghost

i tried all above solutions but not works for me

harishmahajan avatar Aug 30 '17 09:08 harishmahajan

At some point later on I moved most versions up to latest and tried again and it now works. Here are the relevant entries in my package.json "angularfire2": "4.0.0-rc.1", "firebase": "4.1.3",

dovk avatar Aug 30 '17 16:08 dovk

Looks like this may have been solved in the latest release of Firebase 4.2.0

Unfortunately, it isn't. With 4.4.0, the problem is still there. I'm not using angularfire2, though.

derwaldgeist avatar Sep 24 '17 15:09 derwaldgeist

I confirm that it is not working with 4.4.0 but downgrading to 3.3.0 works for me

stevenyap avatar Sep 25 '17 06:09 stevenyap

I got it working by adding cordova-plugin-network-information to my Cordova app. Downgrading to 3.3.0 did not help, since I need phone number auth.

derwaldgeist avatar Sep 25 '17 15:09 derwaldgeist

I have faced the same issue, and i tried most of the solution above (including downgrade to firebase 3.3.0 or add cordova-plugin), and none of them work for me.

I'm currently using firebase 4.4.0. I was able to fix the problem by adding the line below in platform/android --> AndroidManifest.xml.

<uses-permission android:name="android.permission.INTERNET" />

My firebase signin able to go through now after adding the line. Please try see if you can make it work. I not sure why the line is missing out at the beginning.

I not sure if this is the best way of fixing it. But it should the easiest and fastest way (without downgrading or install plugin)

kimmanwky avatar Sep 28 '17 10:09 kimmanwky

I already had this permission in my app. Still, the logon did not work reliably. The only solution I found was to either add the plugin mentioned above or override navigator.onLine to return true every time it is being called. This solved the problem as well, but seemed to be a too weird hack, especially if another plugin relies on this getter variable.

derwaldgeist avatar Sep 28 '17 11:09 derwaldgeist

Can you show the code you added regarding the network plugin and where you added it? I want to check it makes things more stable. Thanks

dovk avatar Sep 28 '17 16:09 dovk

It's this Cordova plugin: https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-network-information/, but this would only make sense if you're building a Cordova application.

What it basically does (that fixes the Firebase problem) is to override the navigator.onLine getter. You could achieve a similar "fix" with this code:

  Object.defineProperty(navigator, 'onLine', {
      get: function() {
        return true;
      },
      set: function() {}
    });

But beware this overrides the standard navigator property onLine with a monkey-patch and thus may break other code that relies on this information. The aforementioned Cordova plugin does more than this, it uses actual native code to implement navigator.onLine.

The main reason why Firebase auth fails is that it relies on navigator.onLine returning a correct connection status. My phone - as many others - report it as false, however, even if there's a working connection. I have no clue why this happens.

derwaldgeist avatar Sep 29 '17 13:09 derwaldgeist