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

Commit 88af90d

Browse files
committed
Merge pull request #316 from facebook/gFosco.40-logout-url
Prevent generation of logout url with app session.
2 parents 566c4ea + 4cc5f76 commit 88af90d

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

src/Facebook/Entities/AccessToken.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,4 +367,14 @@ 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+
return strpos($this->accessToken, "|") !== false;
378+
}
379+
370380
}

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: 18 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,23 @@ 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 = FacebookTestHelper::getAppSession();
84+
$this->setExpectedException(
85+
'Facebook\\FacebookSDKException', 'Cannot generate a Logout URL with an App Session.'
86+
);
87+
$helper->getLogoutUrl(
88+
$session, self::REDIRECT_URL
89+
);
90+
}
7391

7492
public function testCSPRNG()
7593
{

0 commit comments

Comments
 (0)