Get rid of file_get_contents($uri)
Summary: It requires `allow_url_fopen` which we don't check in setup and our installation is about to disable it. Test Plan: Login with OAuth. /oauth/facebook/diagnose/ Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D2787
This commit is contained in:
@@ -86,21 +86,9 @@ final class PhabricatorOAuthDiagnosticsController
|
||||
'Application secret is set.');
|
||||
}
|
||||
|
||||
$timeout = stream_context_create(
|
||||
array(
|
||||
'http' => array(
|
||||
'ignore_errors' => true,
|
||||
'timeout' => 5,
|
||||
),
|
||||
));
|
||||
$timeout_strict = stream_context_create(
|
||||
array(
|
||||
'http' => array(
|
||||
'timeout' => 5,
|
||||
),
|
||||
));
|
||||
$timeout = 5;
|
||||
|
||||
$internet = @file_get_contents("http://google.com/", false, $timeout);
|
||||
$internet = HTTPSFuture::loadContent("http://google.com/", $timeout);
|
||||
if ($internet === false) {
|
||||
$results['internet'] = array(
|
||||
$res_no,
|
||||
@@ -116,7 +104,7 @@ final class PhabricatorOAuthDiagnosticsController
|
||||
|
||||
$test_uris = $provider->getTestURIs();
|
||||
foreach ($test_uris as $uri) {
|
||||
$success = @file_get_contents($uri, false, $timeout);
|
||||
$success = HTTPSFuture::loadContent($uri, $timeout);
|
||||
if ($success === false) {
|
||||
$results[$uri] = array(
|
||||
$res_no,
|
||||
@@ -140,22 +128,23 @@ final class PhabricatorOAuthDiagnosticsController
|
||||
'grant_type' => 'client_credentials',
|
||||
));
|
||||
|
||||
$token_value = @file_get_contents($test_uri, false, $timeout);
|
||||
$token_strict = @file_get_contents($test_uri, false, $timeout_strict);
|
||||
if ($token_value === false) {
|
||||
$future = new HTTPSFuture($test_uri);
|
||||
$future->setTimeout($timeout);
|
||||
try {
|
||||
list($body) = $future->resolvex();
|
||||
$results['App Login'] = array(
|
||||
$res_no,
|
||||
null,
|
||||
"Unable to perform an application login with your Application ID ".
|
||||
"and Application Secret. You may have mistyped or misconfigured ".
|
||||
"them; {$name} may have revoked your authorization; or {$name} may ".
|
||||
"be having technical problems.");
|
||||
} else {
|
||||
if ($token_strict) {
|
||||
$res_ok,
|
||||
'(A Valid Token)',
|
||||
"Raw application login to {$name} works.");
|
||||
} catch (Exception $ex) {
|
||||
if ($ex instanceof HTTPFutureResponseStatusCURL) {
|
||||
$results['App Login'] = array(
|
||||
$res_ok,
|
||||
'(A Valid Token)',
|
||||
"Raw application login to {$name} works.");
|
||||
$res_no,
|
||||
null,
|
||||
"Unable to perform an application login with your Application ID ".
|
||||
"and Application Secret. You may have mistyped or misconfigured ".
|
||||
"them; {$name} may have revoked your authorization; or {$name} ".
|
||||
"may be having technical problems.");
|
||||
} else {
|
||||
$data = json_decode($token_value, true);
|
||||
if (!is_array($data)) {
|
||||
|
||||
@@ -63,7 +63,7 @@ final class PhabricatorOAuthLoginController
|
||||
$userinfo_uri = (string)$userinfo_uri;
|
||||
|
||||
try {
|
||||
$user_data = @file_get_contents($userinfo_uri);
|
||||
$user_data = HTTPSFuture::loadContent($userinfo_uri);
|
||||
if ($user_data === false) {
|
||||
throw new PhabricatorOAuthProviderException(
|
||||
"Request to '{$userinfo_uri}' failed!");
|
||||
@@ -262,34 +262,13 @@ final class PhabricatorOAuthLoginController
|
||||
'code' => $code,
|
||||
) + $provider->getExtraTokenParameters();
|
||||
|
||||
$post_data = http_build_query($query_data, '', '&');
|
||||
$post_length = strlen($post_data);
|
||||
|
||||
$stream_context = stream_context_create(
|
||||
array(
|
||||
'http' => array(
|
||||
'method' => 'POST',
|
||||
'header' =>
|
||||
"Content-Type: application/x-www-form-urlencoded\r\n".
|
||||
"Content-Length: {$post_length}\r\n",
|
||||
'content' => $post_data,
|
||||
),
|
||||
));
|
||||
|
||||
$stream = fopen($auth_uri, 'r', false, $stream_context);
|
||||
|
||||
$response = false;
|
||||
$meta = null;
|
||||
if ($stream) {
|
||||
$meta = stream_get_meta_data($stream);
|
||||
$response = stream_get_contents($stream);
|
||||
fclose($stream);
|
||||
}
|
||||
|
||||
if ($response === false) {
|
||||
$future = new HTTPSFuture($auth_uri, $query_data);
|
||||
$future->setMethod('POST');
|
||||
try {
|
||||
list($response) = $future->resolvex();
|
||||
} catch (Exception $ex) {
|
||||
return $this->buildErrorResponse(new PhabricatorOAuthFailureView());
|
||||
}
|
||||
|
||||
$data = $provider->decodeTokenResponse($response);
|
||||
|
||||
$token = idx($data, 'access_token');
|
||||
|
||||
Reference in New Issue
Block a user