signInWithCredential error code auth/network-request-failed
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.
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!
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:
- Use login form with login button, with or without
ngSubmit, does not matter - Tap and enter email and password
- While device keyboard is still opened, press enter (big right arrow on some keyboards) or the login button and
auth/network-request-failedwill be thrown - Tap somewhere else to close the keyboard, press the login button and
auth/network-request-failedwill be thrown again - 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.
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?
+1
same problem here ... inconsistent and impossible to reproduce for now.
I have this issue with angularfire-4.0.0

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 interesting, so in theory this should help:
Object.defineProperty(navigator, 'onLine', {
get: function() { return true; },
set: function() {}
});
@washowasho THANK YOU SO MUCH!!! Solved it for me!
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
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.
i tried all above solutions but not works for me
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",
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.
I confirm that it is not working with 4.4.0 but downgrading to 3.3.0 works for me
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.
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)
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.
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
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.