Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Commit fd6d9c5

Browse files
author
Fosco Marotto
committed
Prevent generation of logout url with app session.
1 parent 566c4ea commit fd6d9c5

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

src/Facebook/Entities/AccessToken.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,4 +367,17 @@ public function __toString()
367367
return $this->accessToken;
368368
}
369369

370+
/**
371+
* Returns true if the access token is an app session token.
372+
*
373+
* @return bool
374+
*/
375+
public function isAppSession()
376+
{
377+
if (strpos($this->accessToken, "|") !== FALSE) {
378+
return true;
379+
}
380+
return false;
381+
}
382+
370383
}

src/Facebook/FacebookRedirectLoginHelper.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,16 @@ public function getReRequestUrl($scope = array(), $version = null)
143143
* a successful logout
144144
*
145145
* @return string
146+
*
147+
* @throws FacebookSDKException
146148
*/
147149
public function getLogoutUrl(FacebookSession $session, $next)
148150
{
151+
if ($session->getAccessToken()->isAppSession()) {
152+
throw new FacebookSDKException(
153+
'Cannot generate a Logout URL with an App Session.', 722
154+
);
155+
}
149156
$params = array(
150157
'next' => $next,
151158
'access_token' => $session->getToken()

tests/FacebookRedirectLoginHelperTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use Facebook\FacebookRedirectLoginHelper;
44
use Facebook\FacebookRequest;
5+
use Facebook\FacebookSession;
56

67
class FacebookRedirectLoginHelperTest extends PHPUnit_Framework_TestCase
78
{
@@ -70,6 +71,26 @@ public function testLogoutURL()
7071
);
7172
}
7273
}
74+
75+
public function testLogoutURLFailsWithAppSession()
76+
{
77+
$helper = new FacebookRedirectLoginHelper(
78+
self::REDIRECT_URL,
79+
FacebookTestCredentials::$appId,
80+
FacebookTestCredentials::$appSecret
81+
);
82+
$helper->disableSessionStatusCheck();
83+
$session = FacebookSession::newAppSession(
84+
FacebookTestCredentials::$appId,
85+
FacebookTestCredentials::$appSecret
86+
);
87+
$this->setExpectedException(
88+
'Facebook\\FacebookSDKException', 'Cannot generate a Logout URL with an App Session.'
89+
);
90+
$logoutUrl = $helper->getLogoutUrl(
91+
$session, self::REDIRECT_URL
92+
);
93+
}
7394

7495
public function testCSPRNG()
7596
{

0 commit comments

Comments
 (0)