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.pull/5363/head
parent
7716ef059b
commit
ea11a95359
|
@ -93,8 +93,15 @@ class Bitbucket
|
||||||
|
|
||||||
$this->token = json_decode($json, true);
|
$this->token = json_decode($json, true);
|
||||||
} catch (TransportException $e) {
|
} catch (TransportException $e) {
|
||||||
if (in_array($e->getCode(), array(403, 401))) {
|
if ($e->getCode() === 400) {
|
||||||
$this->io->writeError('<error>Invalid consumer provided.</error>');
|
$this->io->writeError('<error>Invalid OAuth consumer provided.</error>');
|
||||||
|
$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('<error>Invalid OAuth consumer provided.</error>');
|
||||||
$this->io->writeError('You can also add it manually later by using "composer config bitbucket-oauth.bitbucket.org <consumer-key> <consumer-secret>"');
|
$this->io->writeError('You can also add it manually later by using "composer config bitbucket-oauth.bitbucket.org <consumer-key> <consumer-secret>"');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -129,9 +129,11 @@ class Git
|
||||||
//We already have an access_token from a previous request.
|
//We already have an access_token from a previous request.
|
||||||
if ($auth['username'] !== 'x-token-auth') {
|
if ($auth['username'] !== 'x-token-auth') {
|
||||||
$token = $bitbucketUtil->requestToken($match[1], $auth['username'], $auth['password']);
|
$token = $bitbucketUtil->requestToken($match[1], $auth['username'], $auth['password']);
|
||||||
|
if (! empty($token)) {
|
||||||
$this->io->setAuthentication($match[1], 'x-token-auth', $token['access_token']);
|
$this->io->setAuthentication($match[1], 'x-token-auth', $token['access_token']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->io->hasAuthentication($match[1])) {
|
if ($this->io->hasAuthentication($match[1])) {
|
||||||
$auth = $this->io->getAuthentication($match[1]);
|
$auth = $this->io->getAuthentication($match[1]);
|
||||||
|
|
Loading…
Reference in New Issue