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

Solution: the issue was corrected in the latest Firebase JavaScript SDK release (4.1.3)

Firebase JavaScript SDK Release Notes

dpassis avatar Jun 24 '17 16:06 dpassis

@dpassis have you tested it? I haven't been following this issue closely so maybe I am doing something wrong. This works on browser:

this.userService.auth.signInWithPopup(new firebase.auth.FacebookAuthProvider()) .then( (success) => { console.log('fb auth success'); this.loading.dismiss(); }).catch( (err) => { console.error(err); }); I get: 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, https or chrome-extension and web storage must be enabled."

I am not without the --prod flag on ionic:

` global packages:

@ionic/cli-utils : 1.4.0                                          
Cordova CLI      : 7.0.1                                          
Ionic CLI        : 3.4.0                                          

local packages:

@ionic/app-scripts              : 1.3.8                           
@ionic/cli-plugin-cordova       : 1.4.0                           
@ionic/cli-plugin-ionic-angular : 1.3.1                           
Cordova Platforms               : android 6.2.3 browser 4.1.0     
Ionic Framework                 : ionic-angular 3.4.2             

System:

Node       : v6.11.0                                              
OS         : Windows 8.1                                          
Xcode      : not installed                                        
ios-deploy : not installed                                        
ios-sim    : not installed                                        
npm        : 4.1.2                                                

`

package.json: "angularfire2": "^4.0.0-rc.1", "firebase": "^4.1.3",

edzillion avatar Jun 24 '17 18:06 edzillion

@edzillion the method signInWithPopup don't work with cordova/ionic, you should use the signInWithRedirect method.

dpassis avatar Jun 24 '17 19:06 dpassis

@dpassis Thanks for the follow up.

I'm running:

  • Firebase 4.1.3:
  • angularfire2: 4.0.0-rc.1
  • ionic-angular: 3.3.0
  • angular: 4.1.2

And i tried the following code in a Android Device with both Google and Facebook providers.

this.afAuth.auth.signInWithRedirect(new firebase.auth.GoogleAuthProvider()).then(result => {
        console.debug(result);
        alert("Success");
      }, error => {
        console.debug(error);
        alert("Failed - " + error.message);
      });

But i keep getting the error:

"This domain (my ip address) is not authorized to run this operation. Add it to the OAuth redirect domains list in the Firebase console -> Auth section -> Sign in method tab"

I already have "localhost" and "my app name" added to the list of domains by default. Doesn't make sense to me that i have to add my ip address to that list. But i tried anyway and still failed.

This might be a silly problem to solve but i'm kinda lost.

Any idea what i'm doing wrong?

mateusmcg avatar Jun 25 '17 00:06 mateusmcg

@mateusmcg make sure that all windows are open by inappbrowser Something like that: function onDeviceReady() { window.open = cordova.InAppBrowser.open; }

Also make sure that all configs listed in the tutorial are done.

dpassis avatar Jun 25 '17 01:06 dpassis

@dpassis Thanks for the quick response

After removing "--livereload" from the command ionic cordova run android i started to get a few errors asking to install a few cordova plugins, which are:

  • cordova-plugin-browsertab
  • cordova-plugin-buildinfo
  • cordova-universal-links-plugin
  • cordova-plugin-inappbrowser

After installing these plugins the google auth page opened normally.

And after chosing my Google Account i'm sent back to the app. But i get no user authenticated within firebase (The promise below returns null):

getAuthenticatedUser() {
    return this.afAuth.authState;
  }

I had to configure a Dynamic Link and a SHA-1 key in the firebase console to get the Google OAuth page to open. Maybe i did something wrong there?

Any idea how to get the authenticated user after selecting the google account and redirecting back to the app?

mateusmcg avatar Jun 25 '17 01:06 mateusmcg

@mateusmcg 1)You need create in the firebase console a android app and add the same id below:

<widget **id="com.app"** version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">

2)You need create a new dynamic link and relate that with your android app created in the step 1, so in the config.xml

<universal-links>
       <host name=**"the link created in the step 2"** scheme="https" />
       <host name=**"https://yourapp.firebaseapp.com"** scheme="https">
           <path url="/__/auth/callback" />
       </host>
   </universal-links>

p.s.: host name is your authDomain, get this in your firebase snnipet

dpassis avatar Jun 25 '17 02:06 dpassis

@dpassis The app is created in firebase and tried to add the universal-links section in the config.xml file like below:

...
<universal-links>
        <host name="https://<my Dynamic Link>" scheme="https" />
        <host name="https://myApp.firebaseapp.com" scheme="https">
            <path url="/__/auth/callback" />
        </host>
</universal-links>
...

But the behavior stayed the same.

Using the code below the success promise is not triggered, instead when i select the google account the app "refreshes" (like opening for the first time) and i get no firebase user authenticated (Went to Firebase Console and there is no user logged in with Google Provider).

this.afAuth.auth.signInWithRedirect(new firebase.auth.GoogleAuthProvider()).then(result => {
        console.debug(result);
        alert("Success");
      }, error => {
        console.debug(error);
        alert("Error");
      });

I think the expected behavior should be the user being redirect back to the app (instead the app reloading entirely again) and that success promise triggered with the authenticated user. Am i doing something wrong here?

mateusmcg avatar Jun 25 '17 03:06 mateusmcg

https://javebratt.com/ionic-social-login-firebase/ Follow this guide...It worked for me

fluentwait avatar Jul 16 '17 09:07 fluentwait

@fluentwait it worked :)

renanss avatar Jul 18 '17 02:07 renanss

I followed this guide indicated by @fluentwait, in addition to this:

https://firebase.google.com/docs/auth/web/cordova?hl=en-us

In special, this step:

3. To handle the case where the app activity is destroyed before the sign-in operation completes, call getRedirectResult when your app loads.

feliperfmarques avatar Dec 20 '17 21:12 feliperfmarques

When I add <univesal-links> tag in config.xml I'm getting this error during build:

Cannot read property 'manifest' of undefined.

Din't you guys get that error to start with ?

cordova-universal-links-plugin seems to have a problem.

bogacg avatar Jan 13 '18 09:01 bogacg

https://javebratt.com/ionic-social-login-firebase/ Follow this guide...It worked for me

alkahtani avatar Mar 21 '18 21:03 alkahtani

When I switched to

import { firebase } from '@firebase/app';

// import these as needed..
import '@firebase/auth'; 
import '@firebase/database'; 
import '@firebase/firestore';

It worked

ToothpickFactory avatar Apr 29 '18 18:04 ToothpickFactory

this artical solved the issue , follow up and let us know.

Ionic Social login

alkahtani avatar May 30 '18 08:05 alkahtani