2011-01-31 20:55:26 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-02-17 18:55:16 +01:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-01-31 20:55:26 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2011-02-21 07:47:56 +01:00
|
|
|
class PhabricatorOAuthDiagnosticsController
|
2011-01-31 20:55:26 +01:00
|
|
|
extends PhabricatorAuthController {
|
|
|
|
|
|
|
|
public function shouldRequireLogin() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-21 07:47:56 +01:00
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->provider = PhabricatorOAuthProvider::newProvider($data['provider']);
|
|
|
|
}
|
|
|
|
|
2011-01-31 20:55:26 +01:00
|
|
|
public function processRequest() {
|
|
|
|
|
2011-02-21 07:47:56 +01:00
|
|
|
$provider = $this->provider;
|
|
|
|
|
|
|
|
$auth_enabled = $provider->isProviderEnabled();
|
|
|
|
$client_id = $provider->getClientID();
|
|
|
|
$client_secret = $provider->getClientSecret();
|
2012-02-17 18:55:16 +01:00
|
|
|
$key = $provider->getProviderKey();
|
|
|
|
$name = phutil_escape_html($provider->getProviderName());
|
2011-01-31 20:55:26 +01:00
|
|
|
|
|
|
|
$res_ok = '<strong style="color: #00aa00;">OK</strong>';
|
|
|
|
$res_no = '<strong style="color: #aa0000;">NO</strong>';
|
|
|
|
$res_na = '<strong style="color: #999999;">N/A</strong>';
|
|
|
|
|
|
|
|
$results = array();
|
2012-02-17 18:55:16 +01:00
|
|
|
$auth_key = $key . '.auth-enabled';
|
2011-01-31 20:55:26 +01:00
|
|
|
if (!$auth_enabled) {
|
2012-02-17 18:55:16 +01:00
|
|
|
$results[$auth_key] = array(
|
2011-01-31 20:55:26 +01:00
|
|
|
$res_no,
|
|
|
|
'false',
|
2012-02-17 18:55:16 +01:00
|
|
|
$name . ' authentication is disabled in the configuration. Edit the '.
|
|
|
|
'Phabricator configuration to enable "'.$auth_key.'".');
|
2011-01-31 20:55:26 +01:00
|
|
|
} else {
|
2012-02-17 18:55:16 +01:00
|
|
|
$results[$auth_key] = array(
|
2011-01-31 20:55:26 +01:00
|
|
|
$res_ok,
|
|
|
|
'true',
|
2012-02-17 18:55:16 +01:00
|
|
|
$name.' authentication is enabled.');
|
2011-01-31 20:55:26 +01:00
|
|
|
}
|
|
|
|
|
2012-02-17 18:55:16 +01:00
|
|
|
$client_id_key = $key. '.application-id';
|
2011-02-21 07:47:56 +01:00
|
|
|
if (!$client_id) {
|
2012-02-17 18:55:16 +01:00
|
|
|
$results[$client_id_key] = array(
|
2011-01-31 20:55:26 +01:00
|
|
|
$res_no,
|
|
|
|
null,
|
2012-02-17 18:55:16 +01:00
|
|
|
'No '.$name.' Application ID is configured. Edit the Phabricator '.
|
2011-01-31 20:55:26 +01:00
|
|
|
'configuration to specify an application ID in '.
|
2012-02-17 18:55:16 +01:00
|
|
|
'"'.$client_id_key.'". '.$provider->renderGetClientIDHelp());
|
2011-01-31 20:55:26 +01:00
|
|
|
} else {
|
2012-02-17 18:55:16 +01:00
|
|
|
$results[$client_id_key] = array(
|
2011-01-31 20:55:26 +01:00
|
|
|
$res_ok,
|
2011-02-21 07:47:56 +01:00
|
|
|
$client_id,
|
2011-01-31 20:55:26 +01:00
|
|
|
'Application ID is set.');
|
|
|
|
}
|
|
|
|
|
2012-02-17 18:55:16 +01:00
|
|
|
$client_secret_key = $key.'.application-secret';
|
2011-02-21 07:47:56 +01:00
|
|
|
if (!$client_secret) {
|
2012-02-17 18:55:16 +01:00
|
|
|
$results[$client_secret_key] = array(
|
2011-01-31 20:55:26 +01:00
|
|
|
$res_no,
|
|
|
|
null,
|
2012-02-17 18:55:16 +01:00
|
|
|
'No '.$name.' Application secret is configured. Edit the '.
|
|
|
|
'Phabricator configuration to specify an Application Secret, in '.
|
|
|
|
'"'.$client_secret_key.'". '.$provider->renderGetClientSecretHelp());
|
2011-01-31 20:55:26 +01:00
|
|
|
} else {
|
2012-02-17 18:55:16 +01:00
|
|
|
$results[$client_secret_key] = array(
|
2011-01-31 20:55:26 +01:00
|
|
|
$res_ok,
|
|
|
|
"It's a secret!",
|
|
|
|
'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,
|
|
|
|
),
|
|
|
|
));
|
|
|
|
|
|
|
|
$internet = @file_get_contents("http://google.com/", false, $timeout);
|
|
|
|
if ($internet === false) {
|
|
|
|
$results['internet'] = array(
|
|
|
|
$res_no,
|
|
|
|
null,
|
|
|
|
'Unable to make an HTTP request to Google. Check your outbound '.
|
|
|
|
'internet connection and firewall/filtering settings.');
|
|
|
|
} else {
|
|
|
|
$results['internet'] = array(
|
|
|
|
$res_ok,
|
|
|
|
null,
|
|
|
|
'Internet seems OK.');
|
|
|
|
}
|
|
|
|
|
2012-02-17 18:55:16 +01:00
|
|
|
$test_uris = $provider->getTestURIs();
|
|
|
|
foreach ($test_uris as $uri) {
|
|
|
|
$success = @file_get_contents($uri, false, $timeout);
|
|
|
|
if ($success === false) {
|
|
|
|
$results[$uri] = array(
|
|
|
|
$res_no,
|
|
|
|
null,
|
|
|
|
"Unable to make an HTTP request to {$uri}. {$name} may be ".
|
|
|
|
'down or inaccessible.');
|
|
|
|
} else {
|
|
|
|
$results[$uri] = array(
|
|
|
|
$res_ok,
|
|
|
|
null,
|
|
|
|
'Made a request to '.$uri.'.');
|
|
|
|
}
|
2011-01-31 20:55:26 +01:00
|
|
|
}
|
|
|
|
|
2012-02-17 18:55:16 +01:00
|
|
|
$test_uri = new PhutilURI($provider->getTokenURI());
|
2011-01-31 20:55:26 +01:00
|
|
|
$test_uri->setQueryParams(
|
|
|
|
array(
|
2011-02-21 07:47:56 +01:00
|
|
|
'client_id' => $client_id,
|
|
|
|
'client_secret' => $client_secret,
|
2011-01-31 20:55:26 +01:00
|
|
|
'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) {
|
|
|
|
$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; ".
|
2012-02-17 18:55:16 +01:00
|
|
|
"{$name} may have revoked your authorization; or {$name} may be ".
|
2011-01-31 20:55:26 +01:00
|
|
|
"having technical problems.");
|
|
|
|
} else {
|
|
|
|
if ($token_strict) {
|
|
|
|
$results['App Login'] = array(
|
|
|
|
$res_ok,
|
2011-04-14 21:20:51 +02:00
|
|
|
'(A Valid Token)',
|
2012-02-17 18:55:16 +01:00
|
|
|
"Raw application login to {$name} works.");
|
2011-01-31 20:55:26 +01:00
|
|
|
} else {
|
|
|
|
$data = json_decode($token_value, true);
|
|
|
|
if (!is_array($data)) {
|
|
|
|
$results['App Login'] = array(
|
|
|
|
$res_no,
|
|
|
|
$token_value,
|
2012-02-17 18:55:16 +01:00
|
|
|
"Application Login failed but the provider did not respond ".
|
|
|
|
"with valid JSON error information. {$name} may be experiencing ".
|
2011-01-31 20:55:26 +01:00
|
|
|
"technical problems.");
|
|
|
|
} else {
|
|
|
|
$results['App Login'] = array(
|
|
|
|
$res_no,
|
|
|
|
null,
|
|
|
|
"Application Login failed with error: ".$token_value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->renderResults($results);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderResults($results) {
|
2012-02-17 18:55:16 +01:00
|
|
|
$provider = $this->provider;
|
2011-01-31 20:55:26 +01:00
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
foreach ($results as $key => $result) {
|
|
|
|
$rows[] = array(
|
|
|
|
phutil_escape_html($key),
|
|
|
|
$result[0],
|
|
|
|
phutil_escape_html($result[1]),
|
|
|
|
phutil_escape_html($result[2]),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$table_view = new AphrontTableView($rows);
|
|
|
|
$table_view->setHeaders(
|
|
|
|
array(
|
|
|
|
'Test',
|
|
|
|
'Result',
|
|
|
|
'Value',
|
|
|
|
'Details',
|
|
|
|
));
|
|
|
|
$table_view->setColumnClasses(
|
|
|
|
array(
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
'wide',
|
|
|
|
));
|
|
|
|
|
2012-02-17 18:55:16 +01:00
|
|
|
$title = $provider->getProviderName() . ' Auth Diagnostics';
|
|
|
|
|
2011-01-31 20:55:26 +01:00
|
|
|
$panel_view = new AphrontPanelView();
|
2012-02-17 18:55:16 +01:00
|
|
|
$panel_view->setHeader($title);
|
2011-01-31 20:55:26 +01:00
|
|
|
$panel_view->appendChild(
|
|
|
|
'<p class="aphront-panel-instructions">These tests may be able to '.
|
|
|
|
'help diagnose the root cause of problems you experience with '.
|
2012-02-17 18:55:16 +01:00
|
|
|
$provider->getProviderName() .
|
|
|
|
' Authentication. Reload the page to run the tests again.</p>');
|
2011-01-31 20:55:26 +01:00
|
|
|
$panel_view->appendChild($table_view);
|
|
|
|
|
|
|
|
return $this->buildStandardPageResponse(
|
|
|
|
$panel_view,
|
|
|
|
array(
|
2012-02-17 18:55:16 +01:00
|
|
|
'title' => $title,
|
2011-01-31 20:55:26 +01:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|