Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using firebase auth with facebook

Tags:

When trying to login to my web app during testing on my android phone, I get this message:

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

I added my firebase url to Valid OAuth redirect URIs on my fb app - https://.firebaseio.com/ I added my app id and name to firebase in auth section. Am i missing something? thanks

I'm using chrome remote debugging here: file:///android_asset/www/index.html#/app/people

Could this be why it's putting up a fuss?

var provider = new firebase.auth.FacebookAuthProvider();

console.log(provider);
  firebase.auth().signInWithPopup(provider).then(function(result) {
 // This gives you a Facebook Access Token. You can use it to access theFacebook API.
   var token = result.credential.accessToken;
// The signed-in user info.
  var user = result.user;
  console.log(user, token);
  UserService.setUser(user, token);
// ...
}).catch(function(error) {
  // Handle Errors here.
  var errorCode = error.code;
  var errorMessage = error.message;
  // The email of the user's account used.
  var email = error.email;
  // The firebase.auth.AuthCredential type that was used.
  var credential = error.credential;
  console.log(errorCode);

  });
like image 605
Bill Pope Avatar asked Jun 11 '16 20:06

Bill Pope


People also ask

Can I use Firebase just for authentication?

You can use Firebase Authentication to allow users to sign in to your app using one or more sign-in methods, including email address and password sign-in, and federated identity providers such as Google Sign-in and Facebook Login.

Does Facebook use Auth0?

Once a user successfully authenticates, Facebook will include an Access Token in the user profile it returns to Auth0. You can use this token to call Facebook's API.

What is app Secret Facebook in Firebase?

The app ID and secret key are unique and are assigned by Facebook. To create the App ID and secret key, visit the following URL: https://developers.facebook.com/. We can add the new application from the My Apps option: We can visit the following URL to add the new project: https://developers.facebook.com/apps/.


1 Answers

Found a work-around in regards to Facebook login which works on Ionic 1 and should in principal also work on Ionic 2.

Add the Cordova plugin cordova-plugin-facebook4 In the auth code, I've added the following:

if ((window.cordova && device.platform == 'iOS') || (window.cordova && device.platform == 'Android')) {
    facebookConnectPlugin.login(['public_profile'], function(result) {
        provider = firebase.auth.FacebookAuthProvider.credential(result.authResponse.accessToken);
        Auth.$signInWithCredential(provider).then(function(authData) {
            // User successfully logged in
        }).catch(function(error) {
            // Login error
        });
    }, function(error) {
        // Login error
    });
} else {
    provider = new firebase.auth.FacebookAuthProvider();
    Auth.$signInWithPopup(provider).then(function(authData) {
        // User successfully logged in
    }).catch(function(error) {
        // Login error
    });
}

Basically, this will make sure that on device it uses the Facebook login SDK while it will use Firebase signInWithPopup when running in a browser

like image 186
Alexis Susset Avatar answered Oct 27 '22 00:10

Alexis Susset