1
0
Fork 0

Minor tweaks and CS fixes to new bitbucket integration, refs #6094

pull/6093/merge
Jordi Boggiano 2017-03-07 15:46:38 +01:00
parent 44ea284ab9
commit c8cf24daad
2 changed files with 10 additions and 9 deletions

View File

@ -54,7 +54,7 @@ class Bitbucket
*/
public function getToken()
{
if (! isset($this->token['access_token'])) {
if (!isset($this->token['access_token'])) {
return '';
}
return $this->token['access_token'];
@ -137,7 +137,7 @@ class Bitbucket
$url = 'https://confluence.atlassian.com/bitbucket/oauth-on-bitbucket-cloud-238027431.html';
$this->io->writeError(sprintf('Follow the instructions on %s', $url));
$this->io->writeError(sprintf('to create a consumer. It will be stored in "%s" for future use by Composer.', $this->config->getAuthConfigSource()->getName()));
$this->io->writeError('Ensure you enter a "Callback URL" or it will not be possible to create an Access Token (this callback url will not be used by composer)');
$this->io->writeError('Ensure you enter a "Callback URL" (http://example.com is fine) or it will not be possible to create an Access Token (this callback url will not be used by composer)');
$consumerKey = trim($this->io->askAndHideAnswer('Consumer Key (hidden): '));
@ -159,7 +159,7 @@ class Bitbucket
$this->io->setAuthentication($originUrl, $consumerKey, $consumerSecret);
if (! $this->requestAccessToken($originUrl)) {
if (!$this->requestAccessToken($originUrl)) {
return false;
}
@ -189,7 +189,7 @@ class Bitbucket
}
$this->io->setAuthentication($originUrl, $consumerKey, $consumerSecret);
if (! $this->requestAccessToken($originUrl)) {
if (!$this->requestAccessToken($originUrl)) {
return '';
}
@ -227,9 +227,10 @@ class Bitbucket
{
$authConfig = $this->config->get('bitbucket-oauth');
if (! isset($authConfig[$originUrl]['access-token']) ||
! isset($authConfig[$originUrl]['access-token-expiration']) ||
time() > $authConfig[$originUrl]['access-token-expiration']
if (
!isset($authConfig[$originUrl]['access-token'])
|| !isset($authConfig[$originUrl]['access-token-expiration'])
|| time() > $authConfig[$originUrl]['access-token-expiration']
) {
return false;
}

View File

@ -600,7 +600,7 @@ class RemoteFilesystem
if ($auth['username'] !== 'x-token-auth') {
$bitbucketUtil = new Bitbucket($this->io, $this->config);
$accessToken = $bitbucketUtil->requestToken($this->originUrl, $auth['username'], $auth['password']);
if (! empty($accessToken)) {
if (!empty($accessToken)) {
$this->io->setAuthentication($this->originUrl, 'x-token-auth', $accessToken);
$askForOAuthToken = false;
}
@ -610,7 +610,7 @@ class RemoteFilesystem
}
if ($askForOAuthToken) {
$message = "\n".'Could not fetch ' . $this->fileUrl . ', please create a bitbucket OAuth token to ' . ($httpStatus === 401 ? 'to access private repos' : 'to go over the API rate limit');
$message = "\n".'Could not fetch ' . $this->fileUrl . ', please create a bitbucket OAuth token to ' . (($httpStatus === 401 || $httpStatus === 403) ? 'to access private repos' : 'to go over the API rate limit');
$bitBucketUtil = new Bitbucket($this->io, $this->config);
if (! $bitBucketUtil->authorizeOAuth($this->originUrl)
&& (! $this->io->isInteractive() || !$bitBucketUtil->authorizeOAuthInteractively($this->originUrl, $message))