From ea11a95359ce942c8b867687699567c0979b0c17 Mon Sep 17 00:00:00 2001 From: Stefan Grootscholten Date: Wed, 8 Jun 2016 21:54:19 +0200 Subject: [PATCH] Provide fallback when using basic authentication. When composer is configured to use bitbucket basic authentication (a bitbucket username and password), you get an error when trying to install dependencies. This commit prevent the install process to be aborted due to uncaught exceptions. --- src/Composer/Util/Bitbucket.php | 11 +++++++++-- src/Composer/Util/Git.php | 4 +++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Composer/Util/Bitbucket.php b/src/Composer/Util/Bitbucket.php index 279ba83fc..e6e64df7a 100644 --- a/src/Composer/Util/Bitbucket.php +++ b/src/Composer/Util/Bitbucket.php @@ -93,8 +93,15 @@ class Bitbucket $this->token = json_decode($json, true); } catch (TransportException $e) { - if (in_array($e->getCode(), array(403, 401))) { - $this->io->writeError('Invalid consumer provided.'); + if ($e->getCode() === 400) { + $this->io->writeError('Invalid OAuth consumer provided.'); + $this->io->writeError('This can have two reasons:'); + $this->io->writeError('1. You are authenticating with a bitbucket username/password combination'); + $this->io->writeError('2. You are using an OAuth consumer, but didn\'t configure a (dummy) callback url'); + + return false; + } elseif (in_array($e->getCode(), array(403, 401))) { + $this->io->writeError('Invalid OAuth consumer provided.'); $this->io->writeError('You can also add it manually later by using "composer config bitbucket-oauth.bitbucket.org "'); return false; diff --git a/src/Composer/Util/Git.php b/src/Composer/Util/Git.php index 8d0c423bd..43422eea8 100644 --- a/src/Composer/Util/Git.php +++ b/src/Composer/Util/Git.php @@ -129,7 +129,9 @@ class Git //We already have an access_token from a previous request. if ($auth['username'] !== 'x-token-auth') { $token = $bitbucketUtil->requestToken($match[1], $auth['username'], $auth['password']); - $this->io->setAuthentication($match[1], 'x-token-auth', $token['access_token']); + if (! empty($token)) { + $this->io->setAuthentication($match[1], 'x-token-auth', $token['access_token']); + } } }