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

Breadcrumb

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

function Bitbucket::authorizeOAuthInteractively

Authorizes a Bitbucket domain interactively via OAuth

Parameters

string $originUrl The host this Bitbucket instance is located at:

string $message The reason this authorization is required:

Return value

bool true on success

Throws

\RuntimeException

TransportException|\Exception

File

vendor/composer/composer/src/Composer/Util/Bitbucket.php, line 138

Class

Bitbucket
@author Paul Wenke <wenke.paul@gmail.com>

Namespace

Composer\Util

Code

public function authorizeOAuthInteractively(string $originUrl, ?string $message = null) : bool {
    if ($message) {
        $this->io
            ->writeError($message);
    }
    $localAuthConfig = $this->config
        ->getLocalAuthConfigSource();
    $url = 'https://support.atlassian.com/bitbucket-cloud/docs/use-oauth-on-bitbucket-cloud/';
    $this->io
        ->writeError('Follow the instructions here:');
    $this->io
        ->writeError($url);
    $this->io
        ->writeError(sprintf('to create a consumer. It will be stored in "%s" for future use by Composer.', ($localAuthConfig !== null ? $localAuthConfig->getName() . ' OR ' : '') . $this->config
        ->getAuthConfigSource()
        ->getName()));
    $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)');
    $storeInLocalAuthConfig = false;
    if ($localAuthConfig !== null) {
        $storeInLocalAuthConfig = $this->io
            ->askConfirmation('A local auth config source was found, do you want to store the token there?', true);
    }
    $consumerKey = trim((string) $this->io
        ->askAndHideAnswer('Consumer Key (hidden): '));
    if (!$consumerKey) {
        $this->io
            ->writeError('<warning>No consumer key given, aborting.</warning>');
        $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;
    }
    $consumerSecret = trim((string) $this->io
        ->askAndHideAnswer('Consumer Secret (hidden): '));
    if (!$consumerSecret) {
        $this->io
            ->writeError('<warning>No consumer secret given, aborting.</warning>');
        $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;
    }
    $this->io
        ->setAuthentication($originUrl, $consumerKey, $consumerSecret);
    if (!$this->requestAccessToken()) {
        return false;
    }
    // store value in user config
    $authConfigSource = $storeInLocalAuthConfig && $localAuthConfig !== null ? $localAuthConfig : $this->config
        ->getAuthConfigSource();
    $this->storeInAuthConfig($authConfigSource, $originUrl, $consumerKey, $consumerSecret);
    // Remove conflicting basic auth credentials (if available)
    $this->config
        ->getAuthConfigSource()
        ->removeConfigSetting('http-basic.' . $originUrl);
    $this->io
        ->writeError('<info>Consumer stored successfully.</info>');
    return true;
}
RSS feed
Powered by Drupal