function Bitbucket::requestAccessToken
2 calls to Bitbucket::requestAccessToken()
- Bitbucket::authorizeOAuthInteractively in vendor/
composer/ composer/ src/ Composer/ Util/ Bitbucket.php - Authorizes a Bitbucket domain interactively via OAuth
- Bitbucket::requestToken in vendor/
composer/ composer/ src/ Composer/ Util/ Bitbucket.php - Retrieves an access token from Bitbucket.
File
-
vendor/
composer/ composer/ src/ Composer/ Util/ Bitbucket.php, line 89
Class
- Bitbucket
- @author Paul Wenke <wenke.paul@gmail.com>
Namespace
Composer\UtilCode
private function requestAccessToken() : bool {
try {
$response = $this->httpDownloader
->get(self::OAUTH2_ACCESS_TOKEN_URL, [
'retry-auth-failure' => false,
'http' => [
'method' => 'POST',
'content' => 'grant_type=client_credentials',
],
]);
$token = $response->decodeJson();
if (!isset($token['expires_in']) || !isset($token['access_token'])) {
throw new \LogicException('Expected a token configured with expires_in and access_token present, got ' . json_encode($token));
}
$this->token = $token;
} catch (TransportException $e) {
if ($e->getCode() === 400) {
$this->io
->writeError('<error>Invalid OAuth consumer provided.</error>');
$this->io
->writeError('This can have three 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');
$this->io
->writeError('3. You are using an OAuth consumer, but didn\'t configure it as private consumer');
return false;
}
if (in_array($e->getCode(), [
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 --global --auth bitbucket-oauth.bitbucket.org <consumer-key> <consumer-secret>"');
return false;
}
throw $e;
}
return true;
}