Unable to signinWithCredential() for Ffacebook OAuth with Firebase - facebook

I've been unable to successfully use Firebase's signinWithCredentials() for a Facebook login. I've checked and rechecked that i'm using the correct app_id and app_secret on Firebase's authentication page as well as confirmed my settings and added a redirect uri to Facebooks developer console.
I'm using a react-native application built on top of expo. My auth flow is to use expo to display the facebook UI and sign the user in.
const { type, token } = await
Facebook.logInWithReadPermissionsAsync('a_secret_number', {
permissions: ['public_profile', 'email']
});
This successfully returns a token which I then try to integrate with firebase by creating a credential:
const credential = await
firebase.auth.FacebookAuthProvider.credential(token);
the credential looks something like:
{
"accessToken": "EAAIgv4Sw9TQBAA1G30ZC71qyjcRLM4o9kWVxf1oGhZAWAdGVeZBHrSdNADHGxCeZCzyWxZAjEPM1iZCXXdsadsadsaga321432432dsaddsadsadas34214234324asdasdsadsapv1W3ybqtziQC4JRKZA5hD4a50JrVC1rfoFiFZAJZCcoGoRViTQtgevbnNEx8s7ZA1a1Xd6xOQBsnZC1qdJzOTgZDZD",
"providerId": "facebook.com",
}
So, up until now i've confirmed the data is formatted correctly and contains something to send to firebase.
Finally,
try {
await firebase.auth().signInWithCredential(credential);
} catch (error) {
console.log(error);
}
And the error message:
{"error":{"errors":[{"domain":"global","reason":"invalid","message":"Unsuccessful debug_token response from Facebook: {\"error\":{\"message\":\"(#100) The App_id in the input_token did not match the Viewing App\",\"type\":\"OAuthException\",\"code\":100,\"fbtrace_id\":\"EpP6p3IVs3a\"}}"}],"code":400,"message":"Unsuccessful debug_token response from Facebook: {\"error\":{\"message\":\"(#100) The App_id in the input_token did not match the Viewing App\",\"type\":\"OAuthException\",\"code\":100,\"fbtrace_id\":\"EpP6p3IVs3a\"}}"}}
After Several hours of headbanging and trying to find solutions for this error, i've come to stack overflow for help. Any help or guidance would be appreciated :)
Module Versions:
"expo": "23.0.0",
"firebase": "^4.10.0",

I had the same issue and resolved it by going to firebase console > Authentication > Sign in method (https://console.firebase.google.com/project/your-project-name/authentication/providers), and editing the facebook provider, inserting the correct App id and App secret from the corresponding fb-app found in the facebook developer dashboard (https://developers.facebook.com/apps/your-app-number/).

Related

How can I solve the error when accessing facebook login

I am new in mobile application. I am trying to do facebook login. I followed this Sample application https://pub.dartlang.org/packages/flutter_facebook_connect
but I am getting error in facebook page like this-
"cannot load URl: this domain URL is not included in api domain. to enable this url uploaded, enter all your app domains and subdomains on the api domain field in your app settings".
Use it this way:
_facebookSignIn() async {
final _facebookConnect = new FacebookConnect(
appId: '<APP_ID>',
clientSecret: '<CLIENT_SECRET>');
FacebookOAuthToken token = await _facebookConnect.login();
//FirebaseUser user = await FirebaseAuth.instance.signInWithFacebook(accessToken: token.access);
// return user;}
You have to follow the instructions at developers.facebook, and add http://localhost:8080 in your app Settings under Products>MyApp>Settings

Facebook API v2.4 : How to get email id of FB user in cordova fb plugin

I'm using " com.phonegap.plugins.facebookconnect " Cordova plugin for FB login in my Phonegap app. My Facebook app is v2.4 . I'm getting only full name and id as login response.But I need email id of user to complete my login process on app.
But when i'm login with same fb credential in my old app i got all details of user as response.This app is connect with facebook app v2.3
Is there any way to get email id of fb user on login ?
My code :
$cordovaFacebook.login(["public_profile", "email", "user_friends"])
.then(function(success) {
//success
}, function (error) {
//error
});
$cordovaFacebook.api("me", ["public_profile"])
.then(function(success) {
//success
} }, function (error) {
//error
});
Thanks in advance
Search for "Declarative Fields" in the changelog: https://developers.facebook.com/docs/apps/changelog#v2_4
You now have to define the fields you want to get in the API calls. The basic call for the /me endpoint would be like this: /me?fields=name,email

HWIOAuthBundle, how to manually authenticate User with a Facebook access token?

I have a website (Symfony2) with HWIOauthBundle used to connect with Facebook and everything works fine.
Now, I'm trying to build an iOS app with Cordova and Ionic framework (AngularJS) and I want to authenticate my user with Facebook :
With $cordovaFacebook, I authenticate my user and get a valid Facebook access token, that's ok
I try to use this access token to authenticate my user on the server-side with HWIOauthBundle :
GET http://..../login/facebook?code=MY_FACEBOOK_ACCESS_TOKEN
Symfony rejects my request with this log :
INFO - Matched route "facebook_login" (parameters: "_route": "facebook_login")
INFO - Authentication request failed: OAuth error: "Invalid verification code format."
So my question is : how can I authenticate my user on both front and back end with Facebook connect?
Thanks :)
I've also been wondering how to implement a server side login with the HWIOAuthBundle.
I didn't find any solution on the web, so I coded the functionnality based on hints I've read on the net.
Basically, you have to :
authenticate the user on your app
make an http request to your server with the Facebook token.
ont the server side, check if the token is for your Facebook app, and retrieve the user's Facebook ID.
Get your user from the DB based on the fetched ID.
Here's my Symfony controller:
public function getSecurityFbAction($token)
{
// Get the token's FB app info.
#$tokenAppResp = file_get_contents('https://graph.facebook.com/app/?access_token='.$token);
if (!$tokenAppResp) {
throw new AccessDeniedHttpException('Bad credentials.');
}
// Make sure it's the correct app.
$tokenApp = json_decode($tokenAppResp, true);
if (!$tokenApp || !isset($tokenApp['id']) || $tokenApp['id'] != $this->container->getParameter('oauth.facebook.id')) {
throw new AccessDeniedHttpException('Bad credentials.');
}
// Get the token's FB user info.
#$tokenUserResp = file_get_contents('https://graph.facebook.com/me/?access_token='.$token);
if (!$tokenUserResp) {
throw new AccessDeniedHttpException('Bad credentials.');
}
// Try to fetch user by it's token ID, create it otherwise.
$tokenUser = json_decode($tokenUserResp, true);
if (!$tokenUser || !isset($tokenUser['id'])) {
throw new AccessDeniedHttpException('Bad credentials.');
}
$userManager = $this->get('fos_user.user_manager');
$user = $userManager->findUserBy(array('facebookId' => $tokenUser['id']));
if (!$user) {
// Create user and store its facebookID.
}
// Return the user's JSON web token for future app<->server communications.
}
I throw the Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException exceptions to handle login errors on my app.
Of course, you really should use https because you will be exchanging sensible information.
I don't know if it's the best way to do it but it works well.
Hope it helps !
Well, I think that Symfony doesn't actually reject your request. Facebook is. I'm not sure if this might help, but I know that a bunch a problems can happen when dealing with the Facebook Auth :
Do you know if the tool sends, along with the code parameter, a redirect_uri parameter ? If so :
Did you check that your redirect_uri HAS a trailing slash at the end ? See this
Silly question, but did you check that your app_id is the same when you got authorized via Cordova ?
Check that your redirect_uri DOES NOT have any query parameter.
Check that the redirect_uri that you use during the whole process is the same all the time.
Overall, it seems that your issue is almost all the time related to the redirect_uri URI format.

Ember Torii facebook authentication not able to get user email

I am using Ember CLI + ember simple auth torii link
to get authentication code from facebook for my ember app.
This is my environment.js file
ENV['torii'] = {
providers: {
'facebook-oauth2': {
apiKey: '865549306850377',
scope: 'email',
//redirectUri: window.document.location.href
redirectUri: 'http://localhost:4200/'
}
}
};
And my login controller looks like this -
facebook: function() {
var _this = this;
this.get('session').authenticate('simple-auth-authenticator:torii', 'facebook-oauth2').then(function(data){
console.log("status - ", _this.get('session'));
});
}
And login.hbs -
<li><button {{action "facebook" "facebook-oauth2"}}>Facebook OAuth2</button></li>
After the user clicks on the link, a facebook popup opens and ember app gets a token.
How do I get the user's email id along with this token ?
Has anybody faced a similar issue ?
So you're using oauth2, so all you're ever going to get is an authorization token. With this token, you can then go off and request other information. The token is basically just there to speed up the validation of users against your application.
If you want to get user information, you would need to create another method (probably on your server-side), which swaps the authorization code for an access token: like so (or alternatively you can request an access token directly, which would remove the need for a server-side solution.
Using the access Token you can then request the Facebook User ID, using the debug token endpoint, and after that you will be able get to any endpoint to get the information you need.

Facebook api - invalid token

tried to send post to facebook api to scrape my page at load.
http://i.stack.imgur.com/3Jd0y.png
what is wrong with my code?
This is how you use FB.api:
FB.api('/', 'post', {
id: 'url-to-scrape',
scrape: true
}, function (response) {
console.log(response);
});
Not sure where you got that code example from, but you should always take a look at the Facebook docs.
I you are getting invalid token means your token is not correct let me tell you how to generate token it is simply by combining your app id and app secret gotten on Facebook developers app dashboard after you have signed up check here and read url and to check errors faster on your code api, download post man here www.getpostman.com, put in your api call code in the url bar and hit send it will tell you your error. Then to get token for facebook fancount,pageid,likescount, you can do a search for more info on graph.facebook.com on google. contact me if there is problem.
$appid = "xxxxxxxxxxxxxxx";
$appsecret = "yyyyyyyyyyyyyyyyyyyyyyyyy";
//get it from your dashboard
$token = $appid .|. $appsecret key