composer: Bitbucket x-token-auth not updating after one hour

I often need to clear my cache due to bitbucket expiring the current x-token-auth after one hour.

With the following composer.json:

{
    "name": "westminster/wts-jobs",
    "version": "1.1",
    "repositories": [
        {
            "type": "git",
            "url": "https://bitbucket.org/westminster/wts-db"
        }
    ],
    "require": {
        "westminster/db": "*"
    },
    "require-dev": {
        "codeception/codeception":"*"
    },
    "config": {
        "bitbucket-oauth": {
            "bitbucket.org" : {
                "consumer-key": "*****",
                "consumer-secret": "*****"
            }
        }
    }
}

The first time I run install, it works. But the x-token-auth which is generated gets saved to the composer cache such that after enough time has elapsed, I get the following:

$ composer update -vvv
Reading ./composer.json
Loading config file /home/mikr/.composer/config.json
Loading config file /home/mikr/.composer/auth.json
Loading config file ./composer.json
Checked CA file /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem: valid
Failed to initialize global composer: Composer could not find the config file: /home/mikr/.composer/composer.json
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section
Reading /home/mikr/Domains/WTS/Projects/wts-jobs/vendor/composer/installed.json
Running 1.1.1 (2016-05-17 12:25:44) with PHP 5.6.15 on Linux / 4.1.13-100.fc21.x86_64
Loading composer repositories with package information
Executing command (/home/mikr/.composer/cache/vcs/https---bitbucket.org-westminster-wts-db/): git rev-parse --git-dir
Executing command (/home/mikr/.composer/cache/vcs/https---bitbucket.org-westminster-wts-db/): git remote -v
Executing command (/home/mikr/.composer/cache/vcs/https---bitbucket.org-westminster-wts-db/): git remote set-url origin 'https://bitbucket.org/westminster/wts-db' && git remote update --prune origin
Executing command (/home/mikr/.composer/cache/vcs/https---bitbucket.org-westminster-wts-db/): git remote set-url origin 'https://://:***@bitbucket.org/westminster/wts-db.git' && git remote update --prune origin
Executing command (CWD): git --version
Failed to update https://bitbucket.org/westminster/wts-db, package information from this repository may be outdated (Failed to execute git remote set-url origin 'https://x-token-auth:***@bitbucket.org/westminster/wts-db.git' && git remote update --prune origin

remote: Invalid username or password. If you log in via a third party service you must ensure you have an account password set in your account profile.
fatal: Authentication failed for 'https://x-token-auth:***@bitbucket.org/westminster/wts-db.git/'
error: Could not fetch origin
)
Executing command (/home/mikr/.composer/cache/vcs/https---bitbucket.org-westminster-wts-db/): git show-ref --tags
Executing command (/home/mikr/.composer/cache/vcs/https---bitbucket.org-westminster-wts-db/): git branch --no-color --no-abbrev -v
Executing command (/home/mikr/.composer/cache/vcs/https---bitbucket.org-westminster-wts-db/): git branch --no-color
Executing command (/home/mikr/.composer/cache/vcs/https---bitbucket.org-westminster-wts-db/): git show 'master':composer.json
Executing command (/home/mikr/.composer/cache/vcs/https---bitbucket.org-westminster-wts-db/): git log -1 --format=%at 'master'
Reading composer.json of westminster/db (v0.1)
Reading /home/mikr/.composer/cache/repo/https---bitbucket.org-westminster-wts-db/27d0e1e4c5ba78b3ba50401cb77c867640c1c72a from cache
Importing tag v0.1 (0.1.0.0)
Reading composer.json of westminster/db (master)
Reading /home/mikr/.composer/cache/repo/https---bitbucket.org-westminster-wts-db/0f0b9040c4733fbe03f666b0d14922e3a155ee52 from cache
Importing branch master (dev-master)
Downloading https://packagist.org/packages.json
Writing /home/mikr/.composer/cache/repo/https---packagist.org/packages.json into cache
Updating dependencies (including require-dev)

My work around is to run:

$ composer clearcache

But it should be taking into account that the generated x-token-auth needs to be refreshed after 1 hour according to bitbucket.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 28 (9 by maintainers)

Commits related to this issue

Most upvoted comments

@tolbon at the moment, your auth.json configuration works. It isn’t in the official documentation.

Yes that would might be good to add @tolbon if you wanna send a PR. Definitely seems like the bitbucket types are missing there.

Hi I have same issue so I spend some time on. I solve this with type of repository. I use ‘vcs’ and my repo finish with .git Otherwise somebody push a modification on RepositoryFactory and add line : $rm->setRepositoryClass('git-bitbucket', 'Composer\Repository\VcsRepository');

and use this at repo type but I don’t know @Seldaek what do you think ? keep vcs and auto-detect or add in FactoryRepo this line of code ?

Ps : do the same for hg-bitbucket

This seems to be a problem still using snapshot. Token is cached and only available for 1 hour.

How to reproduce:

  1. Add a dependency using oauth from bitbucket.
  2. Use composer to download the dependency.
  3. Wait for 1 hour.
  4. Try to use composer update. This will now fail since the token (x-token-auth) only lasts for 1 hour.
cd vendor/username/myrepo
git remote -v 

composer    https://x-token-auth:xxxxxxxx@bitbucket.org/username/myrepo.git (fetch)
composer    https://x-token-auth:xxxxxxxx@bitbucket.org/username/myrepo.git (push)
origin  https://x-token-auth:xxxxxxxx@bitbucket.org/username/myrepo.git (fetch)
origin  https://x-token-auth:xxxxxxxx@bitbucket.org/username/myrepo.git (push

I think one must always generate this token on every composer command or keep a timer on the cached token so that after 1 hour composer will reauthenticate to get a new token.

The workaround

Clear composer cache.

composer clearcache