angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

auth.login() Error "location.protocol" must be http or https

Open Chuckv01 opened this issue 10 years ago • 55 comments

auth.login() has an error when attempting to authenticate with Google or Facebook on an iOS or Android device using Cordova.

Here is a code sample:

this.af.auth.login({
  provider: AuthProviders.Google,
  method: AuthMethods.Popup
}).then((value) => {
  //success
}).catch((error) => {
  console.log(error);
});

Running version 2.0.0-beta.3-0930330 of angularfire2.

When run in a Cordova app the error callback will be called with this message:

screenshot_2016-06-23-15-04-51

Chuckv01 avatar Jun 23 '16 22:06 Chuckv01

Same that #270

quentinchap avatar Jun 24 '16 20:06 quentinchap

Yikes, seems like signInWithPopup() has the same protocol check as getRedirectResult(). https://firebase.google.com/docs/reference/js/firebase.auth.Auth#signInWithPopup

I'm a little out of my depth here on what the right way to solve this is...

jeffbcross avatar Jun 25 '16 00:06 jeffbcross

@davideast can you ask around about this?

jeffbcross avatar Jun 25 '16 00:06 jeffbcross

signInWithRedirect seems to have the same issue than signInWithPopup()

quentinchap avatar Jun 25 '16 16:06 quentinchap

Same issue with credential method and cordova-plugin-facebook4 (http://stackoverflow.com/questions/37768313/using-firebase-auth-with-facebook)


 if (this.platform.is('ios') || this.platform.is('android')) {

        Facebook.login(['public_profile']).then(function (result) {

          console.log("Facebook success: " + JSON.stringify(result));
           authGlob.login(result.authResponse.accessToken, { provider: AuthProviders.Facebook })
            .then((success) => {
              console.log("Firebase success: " + JSON.stringify(success));
            })
            .catch((error) => {
              console.log("Firebase failure: " + JSON.stringify(error));
            });
        })

Facebook success: {"status":"connected","authResponse":{"accessToken":"...","expiresIn":"5110794","session_key":true,"sig":"...","userID":"..."}}

app.bundle.js:500 Firebase failure: {"code":"auth/operation-not-supported-in-this-environment","message":"This operation is not supported in the environment this application is running on. "location.protocol" must be http or https."}

quentinchap avatar Jun 25 '16 17:06 quentinchap

After some correction I find a work around. I propose some add to the documentation #287

quentinchap avatar Jun 26 '16 00:06 quentinchap

Any way to make it work? Thank you.

eusthace811 avatar Jul 08 '16 01:07 eusthace811

looks like some PR is needed for either firebase 3 or angularfire2. also seems that the difficulty now is to specify the area of responsibility which is now a pingpong between firebase, angularfire2 and also the ionic. Actually I'm little confused which is (and if there is any) github repo for JS firebase 3 as firebase package on npmjs.com points to firebase.google.com

So as a first step it would be great to have clear if it is acceptable that i.e. file:// protocol is supposed to be handled, and then if the patch is required on the firebase or angularfire2.

Any suggestions or even better PRs will be very valuable.

ciekawy avatar Jul 08 '16 13:07 ciekawy

does it make sense to add some Help Wanted! or other label to raise the importance/severity? looks like this is actually a blocker for ionic/phonegap apps.

ciekawy avatar Jul 08 '16 13:07 ciekawy

Yes, you're right.

Any news about this?

eusthace811 avatar Jul 11 '16 04:07 eusthace811

I haven't seen any activity on this in awhile. I don't know if cordova support is a priority for the angularfire team at this point.

Chuckv01 avatar Jul 11 '16 14:07 Chuckv01

I guess that it's not about the cordova but about a use case of app loaded from file - there is rather no reason why it should not be supported. And also this was working with firebase 2 (togheter with i.e. https://github.com/ciekawy/angular2-firebase) so this is kind of regression for people moving to new recommended firebase 3 SDK

ciekawy avatar Jul 11 '16 14:07 ciekawy

Since upgrading to firebase 3 in my ionic app I have had many major breaking issues I'm about a month behind :( are there any temporary fixes?

idesignpixels avatar Jul 11 '16 15:07 idesignpixels

I don't know who is developing AngularFire2 but the problem is on the Firebase side.

I contact the Firebase team and this the answer: Are you using popup / redirect sign in methods in Firebase 3.x.x? If so, these methods are currently not supported in native Ionic/Cordova apps. Sorry about that. As a workaround, I recommend to use a library for OAuth such as ngCordova(in Cordova and Ionic apps) and then use auth().signInWithCredential(...) to sign your users in.

cnothegger avatar Jul 12 '16 14:07 cnothegger

@cnothegger Could you elaborate on the fix, I don't understand how using sign in with credentials can login oauth firebase users. Is this something that needs to be pushed to ionic to fix? thanks

idesignpixels avatar Jul 13 '16 11:07 idesignpixels

I think this thread is mixing issues, you can login to firebase using a plugin to get the oauth credentials and pass them through. Yes it is as neatly integrated in to angular fire, but there is a work around

aaronksaunders avatar Jul 13 '16 12:07 aaronksaunders

Solved using Firebase only.

Check this: Advanced: Handle the sign-in flow manually https://firebase.google.com/docs/auth/web/facebook-login

eusthace811 avatar Jul 14 '16 02:07 eusthace811

This seems to be fixed in a cordova environment (specifically Ionic 2) with angularFire2@next but i can't seem to get any auth information. If you subscribe to AngularFire.auth() it never actually fires when the user logs in. Works fine in Chrome. Im guessing this issue is related to this line https://github.com/angular/angularfire2/blob/master/src/auth/auth.ts#L45. Unfortunately that looks like the line that fixed auth.login() not working.

jgw96 avatar Jul 15 '16 22:07 jgw96

@Lindstrom1989 @jgw96 This solution using ionic-native facebook plugin to get the accessToken, creates the credential and then successfully logs in using angularFire2 https://github.com/aaronksaunders/basicaf2

aaronksaunders avatar Jul 16 '16 03:07 aaronksaunders

@aaronksaunders Thank you for the complete working project!

I kept getting typescript build errors til I saw your declare var firebase: any trick.

nelsonad avatar Jul 21 '16 17:07 nelsonad