auth.login() Error "location.protocol" must be http or https
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:

@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 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 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
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
also here similat approach using plugins for facebook and google and also pure web google login option https://github.com/rodrigoreal/ionic2-angularfire-login
I found a quicker approach, used authwithredirect apis from firebase and local-webserver plugin from cordova this works on IOS.
Still an issue in an Ionic 2 app, even with npm install angularfire2@next --save:
Some news? For me it's working fine on Chrome but not on android neither ios.
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.
Some news?
Some news?
some news?
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...
https://market.ionic.io/starters/firebase-v3-auth-social-kit-2 This solved my problem completely
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
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."}
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 .
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, 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.
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).