Login with Facebook OAuth token
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!
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.
Glad you figured this out @zabojnik! Just a heads up that the authentication stuff is changing with the 3.0 SDK.
@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!
On my side i haven't this error with "angularfire2": "^2.0.0-beta.3-0930330" but there is an other issue #279
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.