angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

Uncaught Error: "location.protocol" must be http or https when building to device using Ionic 2 & Angular 2

Open redolds opened this issue 10 years ago • 48 comments

Error in question: This operation is not supported in the environment this application is running on. "location.protocol" must be http or https.

This error only occurs when the app is built & running on a device. In the browser it works great (which is logical).

Maybe there's a way to manually set the location.protocol on a cordova app using Ionic 2?

redolds avatar Jun 18 '16 19:06 redolds

@Chuckv01 i think your issue is a related but a separate issue... related to auth methods that require a popup. In the previous versions the inappbrowser was integrated in the lib to support this functionality

aaronksaunders avatar Jun 23 '16 20:06 aaronksaunders

@aaronksaunders Hmm, I already have the inappbrowser plugin installed in my project. I also gave it a try using AuthMethods.Redirect, but still got the protocol error.

Chuckv01 avatar Jun 23 '16 20:06 Chuckv01

Is there a workaround for this?

nelsonad avatar Jun 26 '16 18:06 nelsonad

@aaronksaunders Would you by chance have this inappbrowser workaround implemented in angularfire2?

Chuckv01 avatar Jun 27 '16 19:06 Chuckv01

@nelsonad as for now, the only workaround I know is to use https://github.com/nraboy/ng2-cordova-oauth and then https://firebase.google.com/docs/auth/web/twitter-login#handle_the_sign-in_flow_manually

olostan avatar Jun 27 '16 22:06 olostan

I'm also still having this issue with [email protected]

ciekawy avatar Jun 30 '16 17:06 ciekawy

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

jsuarezs solution worked. but it requires more effort to handle login and logout. Is there an ETA on when firebase team would allow file:// for ionic?

Vasanth19 avatar Jul 18 '16 21:07 Vasanth19

Using [email protected] fixed my "blank page" issue and I'm able to use the email login of firebase. Facebook and google auth are still broken tho :(

MauricioKruijer avatar Jul 20 '16 13:07 MauricioKruijer

@jlsuarezs , Can you add the code snippet that you used for facebook login... I tried to follow the firebase doc but am not successful.

harpreet2602 avatar Jul 21 '16 16:07 harpreet2602

@harpreet2602 check out @aaronksaunders solution https://github.com/aaronksaunders/basicaf2

This worked for me.

nelsonad avatar Jul 21 '16 20:07 nelsonad

using external auth plugin especially the native one is an interesting option yet this is a workaround and needs additional development especially when the app relays on various auth providers like facebook, google, twitter...

ciekawy avatar Jul 22 '16 20:07 ciekawy

@ciekawy i think that integrating it directly into angularfire2 is the wrong approach for mobile solutions, I believe the correct approach it to provide integration points, like they have and leave it at that...

aaronksaunders avatar Jul 22 '16 20:07 aaronksaunders

Ref: https://github.com/rodrigoreal/ionic2-angularfire-login/issues/4 This is solved here: https://github.com/rodrigoreal/ionic2-angularfire-login

harpreet2602 avatar Jul 23 '16 09:07 harpreet2602

@aaronksaunders I fully agree that from architectural point of view it is better to provide external integrations. However one of the factors to use firebase for my ionic project especially in the early stage was that the authentication (an for a number of providers) was given out of the box.

@harpreet2602 I was able to configure Facebook app to use the approach, yet this is still not a real solution but rather workaround or a replacement - it works just for Facebook (I've managed to make a google plus as well - will try to prepare a PR for that) and requires additional plugin.

still main point is that the real issue concerns firebase SDK

ciekawy avatar Jul 24 '16 11:07 ciekawy

Is a permanent fix in the works? I only use af for the typings and still get this issue. I don't really want to add more complexity by having more libraries handling auth.

idesignpixels avatar Jul 26 '16 08:07 idesignpixels

the response I got from firebase support

I figured it out that Popup/Redirect sign in methods in Firebase 3 are currently not supported in native Ionic/Cordova apps. We are still working on supporting these methods. However, there's no definite timeline on when will this be available.

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.

I guess it's worth asking for the access to firebase SDK sources...

ciekawy avatar Jul 26 '16 09:07 ciekawy

There's a commit not too far back in the tests about a provider for WindowLocation you have to add to the bootstrap providers to get rid of the location.protocol error.

It seems firebase is checking aspects of the location object but is doing so incorrectly causing errors to be thrown. I was looking through the compiled firebase code and in some cases it checks location.protocol === "http" or "https", but then other times where "http:" or "https:" with a colon in the string.

Because of these inconsistent checks I think proceeding with firebase or angular fire for auth isn't a good idea. We've gone the manual route and pass the oauth access token to firebase, it works well, they should add some updates to the setup about the provider for Window location to fix this error.

(Wrote from phone) On Tue, Jul 26, 2016 at 2:56 AM Szymon Stasik [email protected] wrote:

the response I got from firebase support

I figured it out that Popup/Redirect sign in methods in Firebase 3 are currently not supported in native Ionic/Cordova apps. We are still working on supporting these methods. However, there's no definite timeline on when will this be available.

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.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/angular/angularfire2/issues/243#issuecomment-235222788, or mute the thread https://github.com/notifications/unsubscribe-auth/AANjrNTwMW7N6cYSjUNGVtfZtVIOkzbQks5qZdm1gaJpZM4I5A1i .

Sent from my iPhone

gvkhna avatar Jul 26 '16 19:07 gvkhna

Any word on a real fix yet besides the work around??? This issue's been open for a while now and I've seen it come up a lot of other places on the web.

Adtiv avatar Aug 12 '16 17:08 Adtiv

As far as I know, no. In Gitter and other chats, this issue is one of top referenced, but there is no any good workaround or fix.

olostan avatar Aug 13 '16 10:08 olostan