diff --git a/src/Composer/Config.php b/src/Composer/Config.php index 59306f9d2..2bb8d054b 100644 --- a/src/Composer/Config.php +++ b/src/Composer/Config.php @@ -63,6 +63,7 @@ class Config // bitbucket-oauth // github-oauth // gitlab-oauth + // gitlab-token // http-basic ); @@ -125,7 +126,7 @@ class Config // override defaults with given config if (!empty($config['config']) && is_array($config['config'])) { foreach ($config['config'] as $key => $val) { - if (in_array($key, array('bitbucket-oauth', 'github-oauth', 'gitlab-oauth', 'http-basic')) && isset($this->config[$key])) { + if (in_array($key, array('bitbucket-oauth', 'github-oauth', 'gitlab-oauth', 'gitlab-token', 'http-basic')) && isset($this->config[$key])) { $this->config[$key] = array_merge($this->config[$key], $val); } elseif ('preferred-install' === $key && isset($this->config[$key])) { if (is_array($val) || is_array($this->config[$key])) { diff --git a/src/Composer/Util/GitLab.php b/src/Composer/Util/GitLab.php index 1cfe6b15d..6f1dc8683 100644 --- a/src/Composer/Util/GitLab.php +++ b/src/Composer/Util/GitLab.php @@ -64,6 +64,15 @@ class GitLab return true; } + // if available use token from composer config + $authTokens = $this->config->get('gitlab-token'); + + if (isset($authTokens[$originUrl])) { + $this->io->setAuthentication($originUrl, $authTokens[$originUrl], 'private-token'); + + return true; + } + return false; } diff --git a/src/Composer/Util/RemoteFilesystem.php b/src/Composer/Util/RemoteFilesystem.php index 9a16b0d0d..e9d5715fa 100644 --- a/src/Composer/Util/RemoteFilesystem.php +++ b/src/Composer/Util/RemoteFilesystem.php @@ -714,6 +714,9 @@ class RemoteFilesystem if ($auth['password'] === 'oauth2') { $headers[] = 'Authorization: Bearer '.$auth['username']; } + else if ($auth['password'] === 'private-token') { + $headers[] = 'PRIVATE-TOKEN: '.$auth['username']; + } } elseif ('bitbucket.org' === $originUrl && $this->fileUrl !== Bitbucket::OAUTH2_ACCESS_TOKEN_URL && 'x-token-auth' === $auth['username'] ) {