1
0
Fork 0

Debug: display used authentication for http calls

pull/8359/head
Stephan Vock 2019-10-04 16:38:22 +01:00
parent 34a32c31b4
commit 0d1d35c346
1 changed files with 12 additions and 0 deletions

View File

@ -47,6 +47,7 @@ class RemoteFilesystem
private $degradedMode = false; private $degradedMode = false;
private $redirects; private $redirects;
private $maxRedirects = 20; private $maxRedirects = 20;
private $displayedOriginAuthentications = array();
/** /**
* Constructor. * Constructor.
@ -814,24 +815,35 @@ class RemoteFilesystem
} }
if ($this->io->hasAuthentication($originUrl)) { if ($this->io->hasAuthentication($originUrl)) {
$authenticationDisplayMessage = null;
$auth = $this->io->getAuthentication($originUrl); $auth = $this->io->getAuthentication($originUrl);
if ('github.com' === $originUrl && 'x-oauth-basic' === $auth['password']) { if ('github.com' === $originUrl && 'x-oauth-basic' === $auth['password']) {
$options['github-token'] = $auth['username']; $options['github-token'] = $auth['username'];
$authenticationDisplayMessage = 'Using GitHub token authentication';
} elseif ($this->config && in_array($originUrl, $this->config->get('gitlab-domains'), true)) { } elseif ($this->config && in_array($originUrl, $this->config->get('gitlab-domains'), true)) {
if ($auth['password'] === 'oauth2') { if ($auth['password'] === 'oauth2') {
$headers[] = 'Authorization: Bearer '.$auth['username']; $headers[] = 'Authorization: Bearer '.$auth['username'];
$authenticationDisplayMessage = 'Using GitLab OAuth token authentication';
} elseif ($auth['password'] === 'private-token') { } elseif ($auth['password'] === 'private-token') {
$headers[] = 'PRIVATE-TOKEN: '.$auth['username']; $headers[] = 'PRIVATE-TOKEN: '.$auth['username'];
$authenticationDisplayMessage = 'Using GitLab private token authentication';
} }
} elseif ('bitbucket.org' === $originUrl } elseif ('bitbucket.org' === $originUrl
&& $this->fileUrl !== Bitbucket::OAUTH2_ACCESS_TOKEN_URL && 'x-token-auth' === $auth['username'] && $this->fileUrl !== Bitbucket::OAUTH2_ACCESS_TOKEN_URL && 'x-token-auth' === $auth['username']
) { ) {
if (!$this->isPublicBitBucketDownload($this->fileUrl)) { if (!$this->isPublicBitBucketDownload($this->fileUrl)) {
$headers[] = 'Authorization: Bearer ' . $auth['password']; $headers[] = 'Authorization: Bearer ' . $auth['password'];
$authenticationDisplayMessage = 'Using Bitbucket OAuth token authentication';
} }
} else { } else {
$authStr = base64_encode($auth['username'] . ':' . $auth['password']); $authStr = base64_encode($auth['username'] . ':' . $auth['password']);
$headers[] = 'Authorization: Basic '.$authStr; $headers[] = 'Authorization: Basic '.$authStr;
$authenticationDisplayMessage = 'Using HTTP basic authentication with username "' . $auth['username'] . '"';
}
if ($authenticationDisplayMessage && !in_array($originUrl, $this->displayedOriginAuthentications, true)) {
$this->io->writeError($authenticationDisplayMessage, true, IOInterface::DEBUG);
$this->displayedOriginAuthentications[] = $originUrl;
} }
} }