Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 7 additions & 35 deletions src/Facebook/Helpers/FacebookRedirectLoginHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@

use Facebook\Authentication\AccessToken;
use Facebook\Authentication\OAuth2Client;
use Facebook\Url\UrlDetectionInterface;
use Facebook\Url\FacebookUrlDetectionHandler;
use Facebook\Url\FacebookUrlManipulator;
use Facebook\PersistentData\PersistentDataInterface;
use Facebook\Exceptions\FacebookSDKException;
use Facebook\PersistentData\FacebookSessionPersistentDataHandler;
use Facebook\PersistentData\PersistentDataInterface;
use Facebook\PseudoRandomString\PseudoRandomStringGeneratorFactory;
use Facebook\PseudoRandomString\PseudoRandomStringGeneratorInterface;
use Facebook\PseudoRandomString\McryptPseudoRandomStringGenerator;
use Facebook\PseudoRandomString\OpenSslPseudoRandomStringGenerator;
use Facebook\PseudoRandomString\UrandomPseudoRandomStringGenerator;
use Facebook\Exceptions\FacebookSDKException;
use Facebook\Url\FacebookUrlDetectionHandler;
use Facebook\Url\FacebookUrlManipulator;
use Facebook\Url\UrlDetectionInterface;

/**
* Class FacebookRedirectLoginHelper
Expand Down Expand Up @@ -79,7 +77,7 @@ public function __construct(OAuth2Client $oAuth2Client, PersistentDataInterface
$this->oAuth2Client = $oAuth2Client;
$this->persistentDataHandler = $persistentDataHandler ?: new FacebookSessionPersistentDataHandler();
$this->urlDetectionHandler = $urlHandler ?: new FacebookUrlDetectionHandler();
$this->pseudoRandomStringGenerator = $prsg ?: $this->detectPseudoRandomStringGenerator();
$this->pseudoRandomStringGenerator = PseudoRandomStringGeneratorFactory::createPseudoRandomStringGenerator($prsg);
}

/**
Expand Down Expand Up @@ -112,32 +110,6 @@ public function getPseudoRandomStringGenerator()
return $this->pseudoRandomStringGenerator;
}

/**
* Detects which pseudo-random string generator to use.
*
* @return PseudoRandomStringGeneratorInterface
*
* @throws FacebookSDKException
*/
public function detectPseudoRandomStringGenerator()
{
// Since openssl_random_pseudo_bytes() can sometimes return non-cryptographically
// secure pseudo-random strings (in rare cases), we check for mcrypt_create_iv() first.
if (function_exists('mcrypt_create_iv')) {
return new McryptPseudoRandomStringGenerator();
}

if (function_exists('openssl_random_pseudo_bytes')) {
return new OpenSslPseudoRandomStringGenerator();
}

if (!ini_get('open_basedir') && is_readable('/dev/urandom')) {
return new UrandomPseudoRandomStringGenerator();
}

throw new FacebookSDKException('Unable to detect a cryptographically secure pseudo-random string generator.');
}

/**
* Stores CSRF state and returns a URL to which the user should be sent to in order to continue the login process with Facebook.
*
Expand Down