diff --git a/src/Facebook/Helpers/FacebookRedirectLoginHelper.php b/src/Facebook/Helpers/FacebookRedirectLoginHelper.php index 144a5b454..10fc7fab0 100644 --- a/src/Facebook/Helpers/FacebookRedirectLoginHelper.php +++ b/src/Facebook/Helpers/FacebookRedirectLoginHelper.php @@ -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 @@ -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); } /** @@ -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. *