angularfire: 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.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 5
  • Comments: 83 (8 by maintainers)

Most upvoted comments

Hi, I have had the same problem with signInWithCredential which returns an error code auth/network-request-failed on Android, I have yet to test on IOS.

  • firebase#3.1.0
  • angularfire#2.0.1
  • angular#1.5.3
  • ionic#1.3.1

I am posting how I fixed my issue here to hopefully provide a possible solution to someone who may be experiencing the same issue. I have 2 identical ionic projects with the same exact versions of the previously mentioned libraries. The prototype project with the working signInWithCredential which I use to develop new features and my main project. The code in the main project is an exact copy and paste of my previous project yet my main project was having this issue. I found that I had the cordova-plugin-whitelist installed on my prototype project. Installing cordova-plugin-whitelist in my main project and adding the following lines on my config.xml file fixed my issue.


<!-- Don't block any requests -->
<access origin="*" />
<!-- or -->
<access origin="https://*.googleapis.com" />

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.

I am facing this again ! Time to reopen I guess…

+1 for rolling back to Firebase 3.3.0. I’ve been having a problem with intermittent connections to Firebase on Android devices. But rolling back seems to have resolved the issue.

downgrade from 3.7.5 to 3.3.0 works for me.

I have meanwhile moved up to Ionic3/Angular4 and all is well except for having to keep Firebase at 3.3.0 (I tried Firebase@3.4.0 as mentioned above but it did not work). You can see my package.json here https://github.com/dovk/ionic3-calendar (and if anyone is looking for a simple Calendar/Datepicker - feel free to use it)

why was it closed? there are many still facing the same issue. It works only 20% else it would keep showing network error.

For anyone using firebase and phonegap/cordova, I ran into the same issue.

Using firebase version 3.6.1 fixed the issue for me.

angularfire2 dependency for firebase is v3.3.0

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 THANK YOU SO MUCH!!! Solved it for me!

+1

Of all of the suggestions above, the one thing that worked eventually was using “firebase": "3.3.0” instead of “firebase”: “3.7.3” in package.json (enclosed a few posts before). I’m using a very basic login based on an example from Jorge Vergara https://javebratt.com/angularfire2-authentication-ionic/

I just wanted to use simple email/password login for now - I hope adding Facebook and others will eventually work as well. Too bad this is the current situation - Good Luck to us all!

changing the type in my button tag to type=“button” instead of type=“submit” solved this problem for me.

Could someone from the Ionic or AngularFire team please show some direction - perhaps publish the package.json that has been verified to work with the latest versions of AngularFire2+Ionic2. If this could be done every time you put out a new version, it would save so many people so much time and pain. I have spent the past week trying to move to Ionic 2.2, the email authentication stopped working on Android. What is wrong with this ?

“dependencies”: { “@angular/common”: “2.4.8”, “@angular/compiler”: “2.4.8”, “@angular/compiler-cli”: “2.4.8”, “@angular/core”: “2.4.8”, “@angular/forms”: “2.4.8”, “@angular/http”: “2.4.8”, “@angular/platform-browser”: “2.4.8”, “@angular/platform-browser-dynamic”: “2.4.8”, “@angular/platform-server”: “2.4.8”, “@ionic-native/core”: “3.1.0”, “@ionic-native/splash-screen”: “3.1.0”, “@ionic-native/status-bar”: “3.1.0”, “@ionic/storage”: “2.0.0”, “angularfire2”: “^2.0.0-beta.8”, “firebase”: “3.7.3”, “ionic-angular”: “2.3.0”, “ionicons”: “3.0.0”, “rxjs”: “5.0.1”, “sw-toolbox”: “3.4.0”, “zone.js”: “0.7.2” }, “devDependencies”: { “@ionic/app-scripts”: “1.2.2”, “typescript”: “~2.2.1” }, “cordovaPlugins”: [ “cordova-plugin-whitelist”, “cordova-plugin-console”, “cordova-plugin-device”, “cordova-plugin-statusbar”, “cordova-plugin-splashscreen”, “ionic-plugin-keyboard” ], (I also tried the different firebase version like 3.6.1…)

Fixed using firebase 3.6.1 with an ionic project with this configuration Ionic CLI Version: 2.1.13 Ionic App Lib Version: 2.1.7

People that are experiencing it are probably just working around it since it is not a show stopper. You can use another browser or you can skip the message or you can load your dev tools after the app is loaded.

Which is why i had to downgrade the version of firebase after i updated it to 3.6.9.

I just wonder why others are not responding to this issue since many should be facing this very problem!! and why was this issue closed?

angularfire2 beta.7 requires rxjs ^5.0.1, however angular 2.2.1 beta 12 there are more mismatches with versioning that may produce some bugs

@apatton724 I can confirm this. I use angular#1.5.8 ionic#1.3.2 firebase#3.6.1 angularfire#2.3.0

with firebase#3.6.6, when using $firebaseAuth().$signInWithCustomToken on and Android app (6.0 and 4.4) I get the "auth/network request failed even though I have already logged a connection info to the firebase db. This does NOT happen in a browser, or on iOS (same app) only Android app. There seem to be something wrong with the timing of sign-in of firebaseAuth.

if you watch $firebaseAuth.$onAuthStateChanged you will see it fires twice when you use $firebaseAuth().$signInWithCustomToken. Once without a firebaseUser and once with the actual signed in user. (Ver 3.6.1) In ver 3.6.5 and 3.6.6, and 3.6.7 the 2nd $onAuthStateChanged does NOT fire (because the signInWithCustomToken does not complete)

[redacted]

Still, does not work even with firebase 3.6.1. I tried running the app in Firefox or Edge and it worked nicely. I don’t know what is causing this.

I tried it twice , and can confirm we dont get this error on firebase : 3.6.1 version 3.6.5 still has the issue.

So , use version 3.6.1