How to use private Bitbucket repos in composer

If you want to use a private Bitbucket repo in composer, you need to create a OAuth consumer key/secret pair in Bitbucket and configure composer to use that when fetching your repo.

In composer’s docs there’s a helpful article: Authentication for privately hosted packages and repositories

They again link to this page at Atlassian support: Use OAuth on Bitbucket Cloud

In summary:

Bitbucket

  • At Bitbucket, click on your avatar in the bottom left corner and choose a workspace.
  • In the left menu, click Settings and then choose Apps and featuresOAuth consumers and click the button Add consumer.
  • Fill in the name (and optionally a description), and under Permissions select ProjectsRead.
  • Click Save.
  • Click the consumer name to expand the entry and copy Key and Secret.

composer

Add the consumer key and secret to composer’s configuration:

composer config [--global] bitbucket-oauth.bitbucket.org [consumer-key] [consumer-secret]

In composer.json, add the repo as a repository:

    "repositories": [
        ...
        ,{
            "type": "vcs",
            "url": "https://your-username@bitbucket.org/your-workspace/your-repo.git"
        }
        ...
    }

That should be all! Now you can composer install and/or composer update to pull your repo.

(And if you’re balking at that comma, it’s because it makes it easier to cut/paste/move entries around without getting annoyed by missing/trailing comma errors.)