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

How often does this occur? Every time? 10% of the time? How many attempts did you make and over white time period? Can you upgrade to the latest (currently 3.4.0) and try again? If it's still an issue, we'll probably need a jsfiddle or plunkr that reproduces this to be much help, and it's probably not AngularFire-related.

katowulf avatar Oct 05 '16 00:10 katowulf

I am getting the same behavior happen. But I don't know what do to put it on plunkr or jsfiddle. I used this tutorial though: https://playcode.org/getting-started-with-ionic-2-rc0-firebase-3-angularfire-2/

https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key=MYKEYWASHERE Failed to load resource: the server responded with a status of 404 ()

XMLHttpRequest cannot load https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key=MYKEYWASHERE. Response for preflight has invalid HTTP status code 404

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

otherjohn avatar Oct 07 '16 21:10 otherjohn

Damn, right after posting I decided to try loading the code in firefox instead of google chrome. I didn't have an issue! This is a Google Chrome issue. Aggh. I can't believe I wasted so much time on this.

otherjohn avatar Oct 07 '16 21:10 otherjohn

Nice! Well that's a useful note. It's at least a starting point for a fix. What's the minimal code needed to reproduce this? Can it be recreated with vanilla Firebase or only if AngularFire is involved? If we can whittle down the scope just a bit more, I can start looking for a solution.

katowulf avatar Oct 07 '16 21:10 katowulf

I have the following via localhost:8100: // stripped out unnecessary code

The login page has a click action called loginUser() Error happens on clicking the loginUser. login.ts page

import {AngularFire, AuthProviders, AuthMethods} from "angularfire2";

@Component({
    selector: 'page-login',
    templateUrl: 'template.html'
})
export class LoginPage {
    user = {email: '[email protected]', password: 'mypass'}; // used for testing
    constructor(private af: AngularFire) { }
    loginUser(){
         this.af.auth.login(this.user,{
             provider: AuthProviders.Password,
             method: AuthMethods.Password
         }).then((user)  => {
            console.log('user',user);
        }).catch((error) => {
            console.error(error);
        });
    }
}

In firefox it works just fine. In google chrome (Version 53.0.2785.143 (64-bit)) Mac, it does not.

otherjohn avatar Oct 07 '16 23:10 otherjohn

Restart fixed the issue on google chrome.

otherjohn avatar Oct 07 '16 23:10 otherjohn

I actually updated my Ionic to final version of angular 2 and also updated angularfire2 firebase. The issue was not present in the updated version , so I couldn't reproduce it. Can be closed. I think update is the solution

uzumakinaruto123 avatar Oct 08 '16 05:10 uzumakinaruto123

I am having the same with all updated libraries, but only on iOS native. Tried custom auth and anonymous. All work for Android native, as well as webapp chrome, firefox and Safari. Only failing on iOS (tried iOS 9 and 10 + simulator).

Ionic 2.0.0-rc.1 angular 2.0.0 firebase 3.5.1 angularfire2 2.0.0-beta.5

User is being created, but methods are throwing exceptions, which makes it impossible to retrieve the user id. I guess there is some problem with Firebase response codes on iOS.

kleeb avatar Oct 24 '16 20:10 kleeb

I am also on Ionic 2.0.0-rc.1. I notice error as below: screen shot 2016-10-31 at 5 10 55 pm

I already logged in with Google OAuth. It is when I refresh the google chrome browser and see this error. And it is not all the time. It is like 60% of the time when I refresh the browser. I see this. And this is pretty recent as well. Now sure why....

hughred22 avatar Nov 01 '16 00:11 hughred22

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" />

ikabod-bubwit avatar Nov 01 '16 01:11 ikabod-bubwit

@ikabod-bubwit Try your fix and it is not helping on Chorme browser situation (I have not tested on iOs yet). Whitelist plugin is only in Cordova situation NOT in ionic server. I am in Ionic RC2 now and still same problem. The error show up like 80% of the time when hard refresh. Please help!

hughred22 avatar Nov 18 '16 21:11 hughred22

Has anyone managed to solve this problem, I have the same problem in my ionic 2 app

wilsoncx avatar Jan 01 '17 22:01 wilsoncx

I am also getting this same issue. Any solutions??

dcinadr avatar Jan 06 '17 02:01 dcinadr

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

uzumakinaruto123 avatar Jan 06 '17 07:01 uzumakinaruto123

I should note that this only happens when I have dev tools open in chrome.

dcinadr avatar Jan 06 '17 18:01 dcinadr

This is also an issue for me in Ionic RC4 using the latest firebase version

joshgarwood avatar Jan 12 '17 20:01 joshgarwood

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

uzumakinaruto123 avatar Jan 13 '17 09:01 uzumakinaruto123

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.

ghost avatar Jan 13 '17 18:01 ghost

angularfire2 dependency for firebase is v3.3.0

dcinadr avatar Jan 14 '17 05:01 dcinadr

@dcinadr This really did the job mate, thanks a lot!

ghost avatar Jan 14 '17 10:01 ghost