pixelbrackets
pixelbrackets

Reputation: 2318

How to set the Access Token for GitLab instances in Composer?

How do I configure Composer to use an existing Access Token for a GitLab instance?

During composer install I may get a warning that I need an Access Token to pull a package from a GitLab instance. Maybe because the package is private or I reached a API limit. Composer then asks for a username and password to start an OAuth process with the Gitlab instance and fetch the Access Token by itself. What if I don't have the username and password, but I already have an Access Token? How can I set it to let Composer use it the next time?

Upvotes: 3

Views: 17665

Answers (1)

pixelbrackets
pixelbrackets

Reputation: 2318

Composer has a configuration section in the composer file, which may be used for this case. For a GitLab instance multiple options exist, one is to pass an existing Access Token:

https://getcomposer.org/doc/06-config.md#gitlab-token

Schema:

composer config --global gitlab-token.<domain> <access token>

Example:

composer config --global gitlab-token.gitlab.com gbltUW1nWBZcryaX3c9aQcF0

The global argument will set the token for the current user, which means that Composer will use it for all other repositories as well.

The key is stored ~/.composer/auth.json. The same file and command may be used for all services like GitHub, Bitbucket etc.

Check existing settings with composer config --global --list.

Upvotes: 9

Related Questions