Skip to content

Commit 410947d

Browse files
committed
check the state is restored in the constructor
1 parent 21321ff commit 410947d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/base_facebook.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public function __construct($config) {
219219

220220
$state = $this->getPersistentData('state');
221221
if (!empty($state)) {
222-
$this->state = $this->getPersistentData('state');
222+
$this->state = $state;
223223
}
224224
}
225225

tests/tests.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,14 @@ public function testEmptyResponseInCodeExchangeIsIgnored() {
11481148
$this->assertFalse($stub->publicGetAccessTokenFromCode('c', ''));
11491149
}
11501150

1151+
public function testExistingStateRestoredInConstructor() {
1152+
$fb = new FBPublicState(array(
1153+
'appId' => self::APP_ID,
1154+
'secret' => self::SECRET
1155+
));
1156+
$this->assertEquals(FBPublicState::STATE, $fb->publicGetState());
1157+
}
1158+
11511159
public function testMissingAccessTokenInCodeExchangeIsIgnored() {
11521160
$methods_to_stub = array(
11531161
'_oauthRequest',
@@ -1331,3 +1339,17 @@ public function publicGetAccessTokenFromCode($code, $redirect_uri = null) {
13311339
return $this->getAccessTokenFromCode($code, $redirect_uri);
13321340
}
13331341
}
1342+
1343+
class FBPublicState extends TransientFacebook {
1344+
const STATE = 'foo';
1345+
protected function getPersistentData($key, $default = false) {
1346+
if ($key === 'state') {
1347+
return self::STATE;
1348+
}
1349+
return parent::getPersistentData($key, $default);
1350+
}
1351+
1352+
public function publicGetState() {
1353+
return $this->state;
1354+
}
1355+
}

0 commit comments

Comments
 (0)