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

Commit f29580b

Browse files
removed duplicated logic (createPseudoRandomStringGenerator)
1 parent f2ca27a commit f29580b

File tree

1 file changed

+7
-35
lines changed

1 file changed

+7
-35
lines changed

src/Facebook/Helpers/FacebookRedirectLoginHelper.php

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,14 @@
2525

2626
use Facebook\Authentication\AccessToken;
2727
use Facebook\Authentication\OAuth2Client;
28-
use Facebook\Url\UrlDetectionInterface;
29-
use Facebook\Url\FacebookUrlDetectionHandler;
30-
use Facebook\Url\FacebookUrlManipulator;
31-
use Facebook\PersistentData\PersistentDataInterface;
28+
use Facebook\Exceptions\FacebookSDKException;
3229
use Facebook\PersistentData\FacebookSessionPersistentDataHandler;
30+
use Facebook\PersistentData\PersistentDataInterface;
31+
use Facebook\PseudoRandomString\PseudoRandomStringGeneratorFactory;
3332
use Facebook\PseudoRandomString\PseudoRandomStringGeneratorInterface;
34-
use Facebook\PseudoRandomString\McryptPseudoRandomStringGenerator;
35-
use Facebook\PseudoRandomString\OpenSslPseudoRandomStringGenerator;
36-
use Facebook\PseudoRandomString\UrandomPseudoRandomStringGenerator;
37-
use Facebook\Exceptions\FacebookSDKException;
33+
use Facebook\Url\FacebookUrlDetectionHandler;
34+
use Facebook\Url\FacebookUrlManipulator;
35+
use Facebook\Url\UrlDetectionInterface;
3836

3937
/**
4038
* Class FacebookRedirectLoginHelper
@@ -79,7 +77,7 @@ public function __construct(OAuth2Client $oAuth2Client, PersistentDataInterface
7977
$this->oAuth2Client = $oAuth2Client;
8078
$this->persistentDataHandler = $persistentDataHandler ?: new FacebookSessionPersistentDataHandler();
8179
$this->urlDetectionHandler = $urlHandler ?: new FacebookUrlDetectionHandler();
82-
$this->pseudoRandomStringGenerator = $prsg ?: $this->detectPseudoRandomStringGenerator();
80+
$this->pseudoRandomStringGenerator = PseudoRandomStringGeneratorFactory::createPseudoRandomStringGenerator($prsg);
8381
}
8482

8583
/**
@@ -112,32 +110,6 @@ public function getPseudoRandomStringGenerator()
112110
return $this->pseudoRandomStringGenerator;
113111
}
114112

115-
/**
116-
* Detects which pseudo-random string generator to use.
117-
*
118-
* @return PseudoRandomStringGeneratorInterface
119-
*
120-
* @throws FacebookSDKException
121-
*/
122-
public function detectPseudoRandomStringGenerator()
123-
{
124-
// Since openssl_random_pseudo_bytes() can sometimes return non-cryptographically
125-
// secure pseudo-random strings (in rare cases), we check for mcrypt_create_iv() first.
126-
if (function_exists('mcrypt_create_iv')) {
127-
return new McryptPseudoRandomStringGenerator();
128-
}
129-
130-
if (function_exists('openssl_random_pseudo_bytes')) {
131-
return new OpenSslPseudoRandomStringGenerator();
132-
}
133-
134-
if (!ini_get('open_basedir') && is_readable('/dev/urandom')) {
135-
return new UrandomPseudoRandomStringGenerator();
136-
}
137-
138-
throw new FacebookSDKException('Unable to detect a cryptographically secure pseudo-random string generator.');
139-
}
140-
141113
/**
142114
* Stores CSRF state and returns a URL to which the user should be sent to in order to continue the login process with Facebook.
143115
*

0 commit comments

Comments
 (0)