angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

Login with Facebook OAuth token

Open andyfo opened this issue 10 years ago • 5 comments

I would like to use the cordova native facebook plugin in my ionic 2 app to authenticate users. When I authenticate with the plugin, I get userID and accessToken fields. How can I use these fields in the FirebaseAuth.login method?

This is my configuration:

firebaseAuthConfig({
  provider: AuthProviders.Facebook,
  method: AuthMethods.OAuthToken,
  remember: 'default',
  scope: ['email']
})

Thanks!

andyfo avatar Jun 01 '16 10:06 andyfo

I found the correct FirebaseAuth.login call. It looks like this:

this._auth.login({ token: accessToken }, { provider: AuthProviders.Facebook })

The second parameter is needed regardless the firebaseAuthConfig() configuration.

andyfo avatar Jun 01 '16 13:06 andyfo

Glad you figured this out @zabojnik! Just a heads up that the authentication stuff is changing with the 3.0 SDK.

davideast avatar Jun 01 '16 17:06 davideast

@davideast I recently implemented angularfire2 oauth login with facebook access token the same as @zabojnik but I keep getting this error: {"code":"auth/argument-error","message":"signInWithCredential failed: First argument "credential" must be a valid credential."}. Is this due to the new changes? If so, how can I fix it? I have checked and made sure that the access token I am receiving is valid and I have tried several ways of passing it in but all result in this error. I've been looking all over for a solution but this thread seems to be the closest in relevance. Here is the code I am using:

login() {
    Facebook.login(["public_profile", "email", "user_friends"])
      .then((success) => {
        console.log("Facebook success: " + JSON.stringify(success));
        this.af.auth.login(success.authResponse.accessToken, { provider: AuthProviders.Facebook })
          .then((success) => {
            console.log("Firebase success: " + JSON.stringify(success));
          })
          .catch((error) => {
            console.log("Firebase failure: " + JSON.stringify(error));
          });
      })
      .catch((error) => {
        console.log("Facebook failure: " + JSON.stringify(error));
      });
  }

This is also in an Ionic 2 application using angularfire2 v2.0.0-beta.2. Thanks for the help!

Cameron637 avatar Jun 24 '16 02:06 Cameron637

On my side i haven't this error with "angularfire2": "^2.0.0-beta.3-0930330" but there is an other issue #279

quentinchap avatar Jun 25 '16 17:06 quentinchap

I don't think this is related, but just in case it is I am also receiving a "operation has timed out error" that's not being caught but seems to be thrown by my this.af.auth.subscribe call. The app keeps running fine but perhaps that's what's making the login fail.

Cameron637 avatar Jun 27 '16 21:06 Cameron637