composer: bitbucket oauth not working

When I run this command:

composer command -vvv:

I get this output:

You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug
Reading ./composer.json
Loading config file /home/mmoll/.composer/config.json
Loading config file /home/mmoll/.composer/auth.json
Loading config file ./composer.json
Checking CA file /etc/ssl/certs/ca-certificates.crt
Executing command (/tmp/things): git branch --no-color --no-abbrev -v
Failed to initialize global composer: Composer could not find the config file: /home/mmoll/.composer/composer.json
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section
Reading /tmp/things/vendor/composer/installed.json
Reading ./composer.lock
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Reading ./composer.lock
Resolving dependencies through SAT
Dependency resolution completed in 0.008 seconds
Analyzed 180 packages to resolve dependencies
Analyzed 481 rules to resolve dependencies
  - Installing zzz/yyy (1.3.1)
    Cloning 86ee5af60d7c8718fdfaaa07d53e44c2d4adea6c
Executing command (CWD): git clone --no-checkout 'https://bitbucket.org/xxx/yyy.git' '/tmp/things/vendor/zzz/yyy' && cd '/tmp/things/vendor/zzz/yyy' && git remote add composer 'https://bitbucket.org/xxx/yyy.git' && git fetch composer
Executing command (CWD): git config bitbucket.accesstoken
Enter your Bitbucket credentials to access private repos
Follow the instructions on https://confluence.atlassian.com/bitbucket/oauth-on-bitbucket-cloud-238027431.html
to create a consumer. It will be stored in "/home/mmoll/.composer/auth.json" for future use by Composer.
Consumer Key (hidden): 
Consumer Secret (hidden): 
Downloading https://bitbucket.org/site/oauth2/access_token
Failed: [Composer\Downloader\TransportException] The 'https://bitbucket.org/site/oauth2/access_token' URL could not be accessed: HTTP/1.1 400 BAD REQUEST



  [Composer\Downloader\TransportException]                                                                  
  The 'https://bitbucket.org/site/oauth2/access_token' URL could not be accessed: HTTP/1.1 400 BAD REQUEST  


Exception trace:
 () at phar:///home/mmoll/bin/composer.phar/src/Composer/Util/RemoteFilesystem.php:495
 Composer\Util\RemoteFilesystem->callbackGet() at n/a:n/a
 file_get_contents() at phar:///home/mmoll/bin/composer.phar/src/Composer/Util/RemoteFilesystem.php:278
 Composer\Util\RemoteFilesystem->get() at phar:///home/mmoll/bin/composer.phar/src/Composer/Util/RemoteFilesystem.php:99
 Composer\Util\RemoteFilesystem->getContents() at phar:///home/mmoll/bin/composer.phar/src/Composer/Util/Bitbucket.php:87
 Composer\Util\Bitbucket->requestAccessToken() at phar:///home/mmoll/bin/composer.phar/src/Composer/Util/Bitbucket.php:146
 Composer\Util\Bitbucket->authorizeOAuthInteractively() at phar:///home/mmoll/bin/composer.phar/src/Composer/Util/Git.php:123
 Composer\Util\Git->runCommand() at phar:///home/mmoll/bin/composer.phar/src/Composer/Downloader/GitDownloader.php:55
 Composer\Downloader\GitDownloader->doDownload() at phar:///home/mmoll/bin/composer.phar/src/Composer/Downloader/VcsDownloader.php:69
 Composer\Downloader\VcsDownloader->download() at phar:///home/mmoll/bin/composer.phar/src/Composer/Downloader/DownloadManager.php:213
 Composer\Downloader\DownloadManager->download() at phar:///home/mmoll/bin/composer.phar/src/Composer/Installer/LibraryInstaller.php:176
 Composer\Installer\LibraryInstaller->installCode() at phar:///home/mmoll/bin/composer.phar/src/Composer/Installer/LibraryInstaller.php:90
 Composer\Installer\LibraryInstaller->install() at phar:///home/mmoll/bin/composer.phar/src/Composer/Installer/InstallationManager.php:152
 Composer\Installer\InstallationManager->install() at phar:///home/mmoll/bin/composer.phar/src/Composer/Installer/InstallationManager.php:139
 Composer\Installer\InstallationManager->execute() at phar:///home/mmoll/bin/composer.phar/src/Composer/Installer.php:569
 Composer\Installer->doInstall() at phar:///home/mmoll/bin/composer.phar/src/Composer/Installer.php:228
 Composer\Installer->run() at phar:///home/mmoll/bin/composer.phar/src/Composer/Command/InstallCommand.php:134
 Composer\Command\InstallCommand->execute() at phar:///home/mmoll/bin/composer.phar/vendor/symfony/console/Command/Command.php:259
 Symfony\Component\Console\Command\Command->run() at phar:///home/mmoll/bin/composer.phar/vendor/symfony/console/Application.php:844
 Symfony\Component\Console\Application->doRunCommand() at phar:///home/mmoll/bin/composer.phar/vendor/symfony/console/Application.php:192
 Symfony\Component\Console\Application->doRun() at phar:///home/mmoll/bin/composer.phar/src/Composer/Console/Application.php:181
 Composer\Console\Application->doRun() at phar:///home/mmoll/bin/composer.phar/vendor/symfony/console/Application.php:123
 Symfony\Component\Console\Application->run() at phar:///home/mmoll/bin/composer.phar/src/Composer/Console/Application.php:99
 Composer\Console\Application->run() at phar:///home/mmoll/bin/composer.phar/bin/composer:43
 require() at /home/mmoll/bin/composer.phar:25

install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-plugins] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--ignore-platform-reqs] [--] [<packages>]...

And I expected this to happen: OAuth is working and saving the credentials to auth.json

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 29 (10 by maintainers)

Commits related to this issue

Most upvoted comments

If anyone have problems here is details how i fixed this:

/home/USER/.composer/auth.json

{
    "bitbucket-oauth": {
        "bitbucket.org": {
            "consumer-key": "xxxxx",
            "consumer-secret": "yyyyyy"
        }
    }
}

composer.json

{
"repositories": [
      {
        "type": "git",
        "url": "https://bitbucket.org/user/repo.git"
      }
]
}

Bitbucket oauth consumer settings: ( in bitbucket control panel web interface )

  • Callback URL needs to be set to something (e.g. http://example.com ). Dont need to be a valid/your URL!
  • Repo needs to be set to “This is a private consumer”. Else you get 400 error…

Now you should be able to

composer update user/repo

Then , after one hour it will not work anymore as explained here: https://github.com/composer/composer/issues/5389. If you clear the cache composer clearcache you can use composer update user/repo

This worked for me. Instead of relying on auth.json for the credentials, do this instead:

“repositories”: [ { “type” : “git”, “url” : “https://username:password@bitbucket.org/xxx/yyy.git” } ]

If you specify type of repository as “type” : “git” in your composer.json file, change it to “type”: “vcs” and problem will gone.

Had a similar problem when requiring multiple private repositories from bitbucket. @Gorynych #5166 comment did the trick for me.

Configurations that worked are:

"repositories": [
    {
        "type": "git-bitbucket",
        "url": "https://bitbucket.org/some/private-repo.git"
    },
    {
        "type": "vcs",
        "url": "https://bitbucket.org/some/other-repo.git"
    }
]

@Michal-sk have screenshot here showing location

You will need to go to Bitbucket Settings then on the sidebar ACCESS MANAGEMENT > OAuth

When you add or edit an oauth consumer, you will get the screen below (where you can see callback url highlighted)

bitbucket-oauth

Same problem here when trying to have Heroku fetch dependencies from BitBucket using the default Composer version 1.0.0 which was installed on 12-04-2016. By providing our own composer.phar version 1.0-dev (37a1e12672a57813d34251c640be1e3dc0fe4537) 2016-03-27 16:14:51 got deploys working again.

@dzuelke, heads up, multiple Heroku users might experience broken deploys…

After I upgraded to composer v1.0.0 then this happens to me too. If I rollback to 2016-03-29_07-53-57-e8b1a5f it’s ok.