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

@aaronksaunders thanks for the solution, but in my project here i'm not able to use facebook auth only the google one.

So i need to use google authentication that firebase offers with ionic2. There is a workaround for that? (i'm getting that "location.protocol" must be http or https error on login)

mateusmcg avatar Jul 24 '16 02:07 mateusmcg

@mateusmcg I believe you can use the Google Plus plugin for Google oAuth then pass the token to FB the same way: http://ionicframework.com/docs/v2/native/google-plus/

Chuckv01 avatar Jul 24 '16 02:07 Chuckv01

@Chuckv01 thx for the quick reply.

I was not able to make this plugin working with ionic 2. I've only found examples that uses angular 1 not angular 2, so i was not able to import the right module to get the plugin to work.

If someone manage to get ionic2 working with angularfire2/firebase google auth and could post a little piece of code, i would appreciate it

mateusmcg avatar Jul 24 '16 03:07 mateusmcg

We ended up using this code:

https://github.com/timdream/google-oauth2-web-client/blob/master/src/google-oauth2.js

NOTE: we had to change the way the popup passes the token back to the calling context, to use localStorage instead

It does the popup to get the access token.

At which point we pass to firebase like so (after validation of the token at: https://www.googleapis.com/oauth2/v3/tokeninfo?access_token=)

const googleConfig = {
  method: AuthMethods.OAuthToken,
  provider: AuthProviders.Google
};
const creds = (firebase.auth.GoogleAuthProvider as any).credential(null, token);
this.af.auth.login(creds, googleConfig)

ALSO: add this to your providers to get rid of the 'location.protocol must be http'

import { WindowLocation } from "angularfire2";

provide(WindowLocation, {
    useValue: {
      hash: '',
      search: '',
      pathname: '/',
      port: '',
      hostname: 'localhost',
      host: 'localhost',
      protocol: 'https',
      origin: 'localhost',
      href: 'https://localhost/'
    }
  })

NOTE: have to run npm install angularfire2@next --save-dev

gvkhna avatar Jul 27 '16 19:07 gvkhna

also here similat approach using plugins for facebook and google and also pure web google login option https://github.com/rodrigoreal/ionic2-angularfire-login

ciekawy avatar Jul 27 '16 20:07 ciekawy

I found a quicker approach, used authwithredirect apis from firebase and local-webserver plugin from cordova this works on IOS.

srikantk avatar Aug 10 '16 09:08 srikantk

Still an issue in an Ionic 2 app, even with npm install angularfire2@next --save:

img_1369

nunoarruda avatar Aug 10 '16 17:08 nunoarruda

Some news? For me it's working fine on Chrome but not on android neither ios.

RubnC avatar Aug 19 '16 10:08 RubnC

Since this is an issue with the Firebase Authentication SDK, and not related to the AngularFire2 project, the best workaround will continue to be using native auth methods and redirect, as @ciekawy and @gauravk92 have illustrated.

katowulf avatar Sep 01 '16 18:09 katowulf

Some news?

richarddiogo avatar Oct 31 '16 19:10 richarddiogo

Some news?

valterh4ck3r avatar Jan 20 '17 02:01 valterh4ck3r

some news?

hernanbruno97 avatar Jan 24 '17 13:01 hernanbruno97

I sent a email from support firebase,

They answer me with the email :

When you're building an ionic/cordova app (or any app that is running in an environment outside of a browser), then using any of these operations: signInWithPopup(), signInWithRedirect(), linkWithPopup(), and linkWithRedirect() will not work because they do not have a real domain name. Currently the solution to this is to use an OAuth library and then use signInWithCredential(). You can view a similar example here for implementing twitter login.

Hope that helps.

Best Regards, Aye

I can't implement signInWithCredential with google, then i used the facebook auth for my app... This is my workaround...

valterh4ck3r avatar Jan 24 '17 17:01 valterh4ck3r

https://market.ionic.io/starters/firebase-v3-auth-social-kit-2 This solved my problem completely

hernanbruno97 avatar Jan 24 '17 17:01 hernanbruno97

15$ ?

He uses in-app-browser, with option _system browser, this solution is a javascript approach, don't work in native view...

See about : https://ionicthemes.com/tutorials/about/native-facebook-login-with-ionic-framework

valterh4ck3r avatar Jan 24 '17 22:01 valterh4ck3r

I work with Ionic 2.2, Cordova 6.5 and Firebase v3 and have same error using "let provider = new firebase.auth.GoogleAuthProvider(); firebase.auth().signInWithPopup(provider)" or "let provider = new firebase.auth.FacebookAuthProvider(); return firebase.auth().signInWithPopup(provider)" : Error: {"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 and web storage must be enabled."}

diegobdev avatar Jan 27 '17 18:01 diegobdev

15 $? so hard ;s

I will try :" I can't implement signInWithCredential with google, then i used the facebook auth for my app... This is my workaround."

2017-01-27 16:33 GMT-02:00 Diego Borges (diegobdev) < [email protected]>:

I work with Ionic 2.2, Cordova 6.5 and Firebase v3 and have same error using "let provider = new firebase.auth.GoogleAuthProvider(); firebase.auth().signInWithPopup(provider)" or "let provider = new firebase.auth.FacebookAuthProvider(); return firebase.auth().signInWithPopup(provider)" : Error: {"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 and web storage must be enabled."}

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

richarddiogo avatar Jan 27 '17 18:01 richarddiogo

https://market.ionic.io/starters/firebase-v3-auth-social-kit-2 This solved my problem completely

what enviroment do you use?. In the comments sections the author says it not works in ionic view.

alheranx avatar Feb 06 '17 18:02 alheranx

@alheranx, I've just tried that demo app within Ionic View and indeed neither FB nor Google login works. Perhaps, they will work in a standalone iOS and/or Android builds on devices or within emulators, but trying is time intensive. Have a solution that would work within Ionic View would be a time saver for testing.

vkniazeu avatar Mar 14 '17 15:03 vkniazeu

I'm seeing this in QtWeb 3.8.5. It can't even run Gmail, lacks ES6 support (I use Babel to translate to ES5 code), is the same JS engine in the WkhtmlToPdf project (which is HUGELY popular project for converting pages to PDF in a well controlled/formatted manner).

rainabba avatar Apr 17 '17 18:04 rainabba