Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Bitbucket.php

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\Util

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal