Tuesday, February 8, 2022

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

Issue

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?


Solution

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.



Answered By - pixelbrackets

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.