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

Commit

Permalink
Strip 'enforce_https' param
Browse files Browse the repository at this point in the history
  • Loading branch information
yguedidi committed Nov 14, 2018
1 parent 674b2b5 commit 8ecf2d6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Version 5 of the Facebook PHP SDK is a complete refactor of version 4. It comes
- 5.7.0 (2018-00-00)
- Add `joined` to list of fields to be cast to `\DateTime` (#950)
- Add `GraphPage::getFanCount()` to get the number of people who like the page (#815)
- Strip 'enforce_https' param (#1084)
- 5.6.3 (2018-07-01)
- Add fix for countable error in PHP 7.2 (originally #969 by @andreybolonin)
- 5.6.2 (2018-02-15)
Expand Down
4 changes: 2 additions & 2 deletions src/Facebook/Helpers/FacebookRedirectLoginHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ public function getAccessToken($redirectUrl = null)
$this->resetCsrf();

$redirectUrl = $redirectUrl ?: $this->urlDetectionHandler->getCurrentUrl();
// At minimum we need to remove the 'state' and 'code' params
$redirectUrl = FacebookUrlManipulator::removeParamsFromUrl($redirectUrl, ['code', 'state']);
// At minimum we need to remove the 'code', 'enforce_https' and 'state' params
$redirectUrl = FacebookUrlManipulator::removeParamsFromUrl($redirectUrl, ['code', 'enforce_https', 'state']);

return $this->oAuth2Client->getAccessTokenFromCode($code, $redirectUrl);
}
Expand Down
11 changes: 7 additions & 4 deletions tests/Helpers/FacebookRedirectLoginHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class FacebookRedirectLoginHelperTest extends \PHPUnit_Framework_TestCase

const REDIRECT_URL = 'http://invalid.zzz';
const FOO_CODE = "foo_code";
const FOO_ENFORCE_HTTPS = "foo_enforce_https";
const FOO_STATE = "foo_state";
const FOO_PARAM = "some_param=blah";

Expand Down Expand Up @@ -96,15 +97,17 @@ public function testLogoutURL()

public function testAnAccessTokenCanBeObtainedFromRedirect()
{
$this->persistentDataHandler->set('state', 'foo_state');
$_GET['state'] = static::FOO_STATE;
$this->persistentDataHandler->set('state', static::FOO_STATE);

$_GET['code'] = static::FOO_CODE;
$_GET['enforce_https'] = static::FOO_ENFORCE_HTTPS;
$_GET['state'] = static::FOO_STATE;

$fullUrl = self::REDIRECT_URL . '?state=' . static::FOO_STATE . '&code=' . static::FOO_CODE . '&' . static::FOO_PARAM;
$fullUrl = self::REDIRECT_URL . '?state=' . static::FOO_STATE . '&enforce_https=' . static::FOO_ENFORCE_HTTPS . '&code=' . static::FOO_CODE . '&' . static::FOO_PARAM;

$accessToken = $this->redirectLoginHelper->getAccessToken($fullUrl);

// code and state should be stripped from the URL
// 'code', 'enforce_https' and 'state' should be stripped from the URL
$expectedUrl = self::REDIRECT_URL . '?' . static::FOO_PARAM;
$expectedString = 'foo_token_from_code|' . static::FOO_CODE . '|' . $expectedUrl;

Expand Down

0 comments on commit 8ecf2d6

Please sign in to comment.