简体   繁体   中英

Facebook php-sdk writing in response body

I have a problem with the Facebook php-sdk-v4 .
I have a back-end server using Symfony2 and a mobile application as a client.
For authentication, I use the FOSOAuthServerBundle .
I try to use Facebook Login in my mobile app.

To authenticate the user in the mobile app, I use the Android (or IOS) Facebook SDK and retrieve a facebook_access_token and the facebook_userID .

I send them to the server where I check if the facebook_access_token is valid with this code where $socialToken is the facebook_access_token receive from the mobile app and $socialId is the facebook_userID receive from the mobile app :

$facebook = new Facebook(array(
    'app_id'  => self::FACEBOOK_APP_ID,
    'app_secret' => self::FACEBOOK_SECRET,
    'default_graph_version' => 'v2.4',
    'default_access_token' => $socialToken
));
$result = $facebook->get('/me');
$this->socialDetails = $result->getGraphUser();
if ($this->socialDetails->getId() != $socialId) {
    $this->logger->info("checkFacebookAccessToken : Token is NOT valid");
    return false;
}
$this->logger->info("checkFacebookAccessToken : Token is valid");
return true;

This code is working fine. Once the token validated, I forward the request to the FOSOAuthServerController to generate an access token and return this access_token to the mobile app with :

return $response = $this->get('fos_oauth_server.controller.token')->tokenAction($request);

This code is working too. But the problem is that the response body send to the mobile app is the following :

object(Facebook\GraphNodes\GraphUser)#616 (1) {
     ["items":protected]=>
     array(2) {
         ["name"]=>
             string(16) "John Doe"
         ["id"]=>
             string(15) "123456789012345"
     }
}
{
    "access_token":"myAccessToken",
    "expires_in":3600,
    "token_type":"bearer",
    "scope":null,
    "refresh_token":"myRefreshToken"
}

instead of :

{
    "access_token":"myAccessToken",
    "expires_in":3600,
    "token_type":"bearer",
    "scope":null,
    "refresh_token":"myRefreshToken"
}

It seems that Symfony appends the 2 responses body . But when I log the response return by the FOSOAuthServerBundle controller it only displays the second response.

Maybe the Facebook php-sdk writes directly in the response body. Is there a way to delete the content of the response body before forwarding the request to the FOSOAuthServerBundle controller ?

It looks like you forgot a var_dump($this->socialDetails); somewhere in your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM